linux 监控服务脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 
#!/bin/sh
weblist=/shell/web_monit/weblist.txt
for list in `cat $weblist|grep -E -v "#|^$"`
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 = 500 ]||[ $httpcode = 502 ]||[ $httpcode = 503 ]||[ $httpcode = 504 ]
then
curl -d "mobile=13800008888&text=访问 $list 超时" "http://127.0.0.1/sms/"
else
echo "$list is checked ok!"
fi

if [ $httptime -ge 3000 ]
then
curl -d "mobile=13800008888&text=访问 $list 超时" "http://127.0.0.1/sms/"
else
echo "$list is connect ok!"
fi
done

{———-}

同目录下 建立 weblist.txt

1
2
http:www.wuxinvip.com
https://www.wuxinvip.com