监控网站状态

#!/bin/bash
weblist="/home/tkm/jiankongurl200/url.txt"
myemail="754347404@qq.com,362318118@qq.com"
> /home/tkm/jiankongurl200/jiankong1.log #清空之前的资源
file=/home/tkm/jiankongurl200/jiankong1.log
ab=0 #计数 检测三次
for i in `seq 1 3`

do 
   for list in `cat $weblist|grep -E -v "#|^$"`;do
       httpcode=`curl -A "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko)                                                                                                Chrome/30.0.1599.101 Safari/537.36" -i -m 10 -o /dev/null -s -w %{http_code} "$list"`

      if [ $httpcode = 200 ]||[ $httpcode = 301 ]||[ $httpcode = 302 ];then 
        echo "$list is checked ok!"
      else
      let ab++ 
      echo $i 
      echo "Warning: down !"
      echo "这个url="$list"出问题了,错误状态"$httpcode >> /home/tkm/jiankongurl200/jiankong1.log
      cat /home/tkm/jiankongurl200/jiankong1.log >> /home/tkm/jiankongurl200/jiankongout.log
   fi
done
done
if [ $ab = 3 ];then
cat $file|sort|uniq -c|awk '{if($1=3) print $2}'|mail -s 'url报警' $myemail
fi
>  /home/tkm/jiankongurl200/jiankong1.log

我来吐槽

*

*