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

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

#!/bin/sh
#author:hzsnone@163.com
#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" xxx@xxx.com
fi
if [ $httptime -ge 10000 ]
then
        echo "At $getdate,$list is timeout !,please check it and fixed now"|mail -s "webtimeout" xxx@xxx.com
else
echo "At $getdate,$list is connect ok!">> $webcheckmsg
fi
done

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值