#!/bin/bash #Author Template #Time 2018-07-01 16:00 url_list=( http://www.cnblogs.com/Template/ http://www.baidu.com http://127.0.0.1 ) . /etc/init.d/functions function wait(){ echo -n "3 秒后执行检查." for ((i=0;i<3;i++)) do echo -n "." ;sleep 1 done echo } function check_url(){ wait for ((i=0;i<`echo ${#url_list[*]}`;i++)) do wget -o /dev/null -T 3 --tries=1 --spider ${url_list[$i]} &> /dev/null if [ $? -eq 0 ];then action "${url_list[$i]}" /bin/true else action "${url_list[$i]}" /bin/false fi ((check_count++)) done } main(){ while true do check_url echo "------------check count:${check_count}------------------" sleep 10 done } main
版本2:
#!/bin/bash #Author=Template #Time 2018-07-04 21:39 . /etc/init.d/functions check_count=0 url=( https://www.cnblogs.com/Template/ www.baidu.com www.google.com http://localhost ) wait(){ echo "3秒后,执行检查URL的操作" for ((i=0;i<3;i++)) do echo -n ".";sleep 1 done echo } chk_url(){ for ((i=0;i<${#url[*]};i++)) do wget -o /dev/null -T 3 --tries=1 --spider ${url[$i]} &> /dev/null if [ $? -eq 0 ];then action "${url[$i]}" /bin/true else action "${url[$i]}" /bin/false fi done ((check_count++)) } main(){ while true do chk_url echo ----------check count:$check_count---------- sleep 2 done } main