shell脚本-监控web可用性

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

写一个shell脚本,通过curl -I 返回的状态码来判定所访问的网站是否正常。比如,当状态码为200时,才算正常。

#!/bin/bash
#Judge the website OK or not OK
#Written by Adai 2017-09-13
read -p "Please input domain name (eg:www.xxx.com) :" w
n=`curl $w -I |grep 'HTTP' |awk '{print $2}'`
if [ $n -eq 200 ]
then
    echo "The website working well!"
else
    echo "Bad site!"
fi

阿铭:

#/bin/bash
url="http://www.apelearn.com/index.php"
sta=`curl -I $url 2>/dev/null |head -1 |awk '{print $2}'`
if [ $sta != "200" ]
then
    python /usr/local/sbin/mail.py [email protected] "$url down." "$url down"
fi

转载于:https://my.oschina.net/adailinux/blog/1537629

你可能感兴趣的:(shell脚本-监控web可用性)