TA的每日心情 | 开心 昨天 22:18 |
---|
签到天数: 1645 天 [LV.Master]伴坛终老
|
利用shell脚本判断网站访问是否正常,以下是个人写的脚本
#!/bin/bash
#auth:created by wanghao
#email:1074189538@qq.com
#func:judge url address ok or failed
. /etc/init.d/functions
address=(
https://bbs.cnblackhat.com
http://www.cnblackhat.com
http://192.168.43.234
)
function Wait() {
echo -n '3秒后,执行该操作'
for((i=0;i<3;i++))
do
echo -n ".";sleep 1
done
echo
}
function check_url() {
Wait
echo 'check url...'
for((i=0;i<${#address[@]};i++))
do
judge=($(curl -I -s --connect-timeout 2 ${address[$i]}|head -1|tr "\r" "\n"))
if [ "${judge[1]}" == "200" -a "${judge[2]}" == "OK" ];then
# echo "${judge[1]} ${judge[2]}"
action "${address[$i]}" /bin/true
else
# echo "${judge[1]} ${judge[2]}"
action "${address[$i]}" /bin/false
fi
done
}
check_url
效果图:
|
|