写一个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 xxx@qq.com "$url down." "$url down"
fi
(adsbygoogle = window.adsbygoogle || []).push({});