shell 脚本检测网站存活
#!/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
c
u
r
l
−
s
−
o
/
d
e
v
/
n
u
l
l
h
t
t
p
:
/
/
i curl -s -o /dev/null http://
icurl−s−o/dev/nullhttp://i
if [ KaTeX parse error: Expected 'EOF', got '#' at position 29: …en #̲echo "i is ok"
action “KaTeX parse error: Expected 'EOF', got '#' at position 35: …se #̲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
c
u
r
l
−
s
−
o
/
d
e
v
/
n
u
l
l
h
t
t
p
:
/
/
i curl -s -o /dev/null http://
icurl−s−o/dev/nullhttp://i
if [ KaTeX parse error: Expected 'EOF', got '#' at position 29: …en #̲echo "i is ok"
action “KaTeX parse error: Expected 'EOF', got '#' at position 35: …se #̲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} 控制额外输出