批量检查多个网站地址是否正常
要求:shell数组方法实现,检测策略尽量模拟用户访问思路
http://www.baidu.com
http://www.taobao.com
http://192.168.0.17
脚本
#!/bin/bash
[ -f /etc/init.d/functions ]&& . /etc/init.d/functions
array=(
http://www.etiantian.org
http://www.taobao.com
http://oldboy.blog.51cto.com
http://10.0.0.7
)
wait(){
echo -n "wait 3s"
for((i=0;i<=3;i++))
do
echo -n "."
sleep 1
done
echo
}
check_url(){
wget -T 5 -t 2 --spider $1 &>/dev/null
RETVAL=$?
if [ $RETVAL -eq 0 ];then
action "check $1" /bin/true
else
action "check $1" /bin/false
fi
return $RETVAL
}
main(){
wait
for((i=0;i<${#array[@]};i++))
do
check_url ${array[i]}
done
}
main