#!/bin/bash
. /etc/init.d/functions

check_fun(){
url_list=(www.baidu.com www.youku.com www.tudou.com www.xxxxxx55555555555555555555555xxxxxxxxxx.com)
for i in ${url_list[@]}
do
	#echo $i
	curl -s -o /dev/null http://$i
	if [ $? -eq 0 ]; then
        	#echo "$i is ok"
		action "$i" /bin/true
	else
        	#echo "$i not ok"
		action "$i" /bin/false
	fi

done
}
while :
do
	check_fun	
	sleep 3
done

 

[root@master ~]# cat check_url_2.sh 
#!/bin/bash
. /etc/init.d/functions

check_fun(){
#url_list=(www.baidu.com www.youku.com www.tudou.com www.xxxxxx55555555555555555555555xxxxxxxxxx.com)
#for i in ${url_list[@]}
while read i
do
	#echo $i
	curl -s -o /dev/null http://$i
	if [ $? -eq 0 ]; then
        	#echo "$i is ok"
		action "$i" /bin/true
	else
        	#echo "$i not ok"
		action "$i" /bin/false
	fi

done < /tmp/url.txt
}
while :
do
	check_fun	
	sleep 3
done

 curl -I -m 10 -o /dev/null -s -w %{http_code} www.baidu.com

  • -I 仅测试HTTP头
  • -m 10 最多查询10s
  • -o /dev/null 屏蔽原有输出信息
  • -s silent 模式,不输出任何东西
  • -w %{http_code} 控制额外输出