Centos下使用Shell实现批量监控站点状态码,发邮件告警

监控所有站点的状态,是否可以打开,使用curl获取状态码判定,以及超时检查,超时10s也发送邮件报警

#!/bin/sh
#author:[email protected]
#function:check all websit is ok or not
#date:2016-04-20
weblist=/root/weblist.txt
getdate=`date +"%Y-%m-%d %H:%M:%S"`
webcheckmsg=/root/webcheckmsg.txt
for list in `cat $weblist`
do
httpcode=`curl -o /dev/null -s -w %{http_code} "$list"`
httptime=`curl -o /dev/null -s -w "time_connect: %{time_connect}\ntime_starttransfer: %{time_starttransfer}\ntime_total: %{time_total}\n" "$list"|grep time_total|awk -F ":" '{print $2*1000}'`
if [ $httpcode = 200 ]||[ $httpcode = 301 ]||[ $httpcode = 302 ]
then
echo "At $getdate,$list is checked ok!">> $webcheckmsg
else
        echo "At $getdate ,$list is dead,please check it and fixed now"|mail -s "webdead" [email protected]
fi
if [ $httptime -ge 10000 ]
then
        echo "At $getdate,$list is timeout !,please check it and fixed now"|mail -s "webtimeout" [email protected]
else
echo "At $getdate,$list is connect ok!">> $webcheckmsg
fi
done

猜你喜欢

转载自blog.csdn.net/qq625281334/article/details/85272179