跳转至

61. 脚本:批量检查多个网站

9. 批量检查多个网站地址是否正确

要求:

1.使用shell数组方法实现,检测策略尽量模拟用户访问

2.每10秒做一次所有的检测,无法访问的输出报警

3.待检测网址如下

http://blog.oldboyedu.com

http://blog.etiantian.org

http://www.luffycity.com

http://10.0.0.7

#!/bin/bash
. /etc/init.d/functions
URL=(
http://blog.oldboyedu.com
http://blog.etiantian.org
http://www.luffycity.com
http://10.0.0.7
)

CheckUrl(){
    wget -t 2 -T 5 -o /dev/null -q $1
    if [ $? -eq 0 ];then
        action "$1 is ok" /bin/true
    lese
        action "$1 is fail" /bin/false
    fi
}

DealUrl(){
    for((i=0;i<${#URL[*]};i++))
    do
        CheckUrl ${URL[i]}
    done
}

main(){
    while true
    do
        DealUrl
        sleep 10
        echo "--------------------------------"
    done
}
main

方法2

vim url.log
http://blog.oldboyedu.com
http://blog.etiantian.org
http://www.luffycity.com
http://10.0.0.7
#!/bin/bash
. /etc/init.d/functions

CheckUrl(){
    wget -t 2 -T 5 -o /dev/null -q $1
    if [ $? -eq 0 ];then
        action "$1 is ok" /bin/true
    lese
        action "$1 is fail" /bin/false
    fi
}

DealUrl(){
    while read line
    do
        CheckUrl $line
    done <./url.log
}

main(){
    while true
    do
        DealUrl
        sleep 10
        echo "--------------------------------"
    done
}
main

最后更新: 2022-02-19 13:59:07