linux shell|linux中利用shell监控网站状态

更新时间:2018-08-25    来源:linux    手机版     字体:

【www.bbyears.com--linux】

今天给自己的网站写了shell监控,避免网站挂了我都不知道,这个脚本是分别检查网页状态和网页连接时间,还可以根据自己的需要进行扩展,很强大.
脚本内容:
vi check-web.sh

 代码如下 #!/bin/sh
weblist=/root/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 = 200 ]||[ $httpcode = 301 ]||[ $httpcode = 302 ]||[ $httpcode = 403 ]||[ $httpcode = 401 ]
if [ $httpcode = 200 ]||[ $httpcode = 301 ]||[ $httpcode = 302 ]
then
echo "$list is checked ok!"
else
echo "$list is down!" | mutt -s "web is down" rocdk@163.com
fi
if [ $httptime -ge 10000 ]
then
echo "$list is timeout!" | mutt -s "web is timeout" rocdk@163.com
else
echo "$list is connect ok!"
fi
done

然后创建要检查网站的列表,格式为http://xxx.xxx.xxx

 代码如下 touch /root/weblist.txt
http://blog.slogra.com

chmod +x /root/soft_shell/check-web.sh

crontab -e
*/3 * * * * /bin/sh /root/soft_shell/check-web.sh


手动运行后的图如下


点击查看原图
好了,这下可以放心了.

本文来源:http://www.bbyears.com/caozuoxitong/43852.html