方法一:
[root@Centos-6 script]# vi check_url_01.sh #!/bin/sh
#this script is created by nulige
#check url add
#version1.1
. /etc/init.d/functions url_list=(
http://www.baidu.com
http://www.qq.com
http://192.168.146.128
) function wait()
{
echo -n '3秒后,执行该操作';
for ((i=0; i<3; i++))
do
echo -n ".";sleep 1
done
echo
} function check_url(){
set -x
wait
set +x
echo 'check url...'
for ((i=0; i<${#url_list[*]}; i++))
do
#HTTP/1.1 200 OK
judge=($(curl -I -s ${url_list[$i]}|head -1|tr "\r" "\n"))
if [[ "${judge[1]}" == '' && "${judge[2]}"=='OK' ]]
then
action "${url_list[$i]}" /bin/true
else
action "${url_list[$i]}" /bin/false
fi
done
}
check_url
执行结果:
[root@Centos-6 script]# sh check_url_01.sh
3秒后,执行该操作;...
check url...
http://www.baidu.com [确定]
http://www.qq.com [确定]
http://192.168.1.7 [确定]