# auth by shikun.zhou - EMail:shikun.zhou@bdqn.cn
# Last modified: 2018-1-15
# Filename: check_url.sh
# Description: wget monitoring web is normal
#====================================================
while true
do
Mail="shikun.zhou@bdqn.cn"
FailCount=0
Retval=0
GetUrlStatus(){
for ((i=1;i<=3;i++))
do
wget -T 3 --tries=1 --spider {1} >> /dev/null ##-T超时时间,--tries尝试1次,--spider蜘蛛
[ $? -ne 0 ] && let FailCount+=1; ##访问超时时,$?不等于0,则FailCount加1
done
if [ $FailCount -gt 1 ];then
Retval=1
Date=`date +%F" "%H:%M`
/usr/local/bin/sendEmail -f www@bdqn.cn -t shikun.zhou@bdqn.cn -s pbmail.bdqn.cn -u "check_url" -m "Date: $Date\nProblem: $url is not running"
else
Retval=0
fi
return $Retval
}
for url in `cat url.txt | sed '/^#/d'`
do
#$GetUrlStatus $url && echo yes || echo no
GetUrlStatus $url
done
sleep 2m
done