linux中利用shell監控網站狀態

來源:互聯網
上載者:User

我們現在網站都會使用一些工具監控網站伺服器是否可以訪問,但不能監控網站的狀態,下面我來給大家推薦一個linux中利用shell監控網站狀態指令碼。

今天給自己的網站寫了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


手動運行後的圖如下



好了,這下可以放心了.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.