新的博客站終於備案並遷移成功 http://www.showerlee.com
web
有須要的小夥伴能夠站內向我諮詢,絕對免費哦.bash
51CTO同時做爲個人備份博客站同步發佈個人最新博文,歡迎你們的訪問.併發
最近恰好須要測試一下新建站的穩定性,因此寫了個SHELL腳本放到本機(最近換了mac本),可以實時查看你須要監控的WEB頁面狀態,併發送到指定郵箱.curl
這裏贊一下OS X自帶有crontab計劃任務,能夠直接在本機測試腳本啦^_^ide
# vi check_web_alive.sh
測試
---------------------------------------------------------------------
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
# define url
WEB_URL=("http://www.example.com" "http://www1.example.com" "http://www2.example.com")
# check network
NET_ALIVE=$(ping -c 5 8.8.8.8 |grep 'received'|awk 'BEGIN {FS=","} {print $2}'|awk '{print $1
}')
if [ $NET_ALIVE == 0 ]; then
echo "Network is not active,please check your network configuration!"
exit 0
fi
# check url
for((i=0; i!=${#WEB_URL[@]}; ++i))
{
ALIVE=$(curl -o /dev/null -s -m 10 -connect-timeout 10 -w %{http_code} ${WEB_URL[i]} |grep
"000000")
if [ "$ALIVE" == "000000" ]; then
echo "'${WEB_URL[i]}' can not be open,please check!" | mail -s "Website Notification to $
{WEB_URL[i]}" yourname@example.com
echo "failed"
else
echo "'${WEB_URL[i]}' is OK!"
fi
}url
---------------------------------------------------------------------
code