shell 實現監控Web服務狀態
阿新 • • 發佈:2017-05-22
web 監控
使用shell 實現監控Web服務狀態
原理:下載網站,並把輸出寫入 /dev/null,如果該命令執行結果成功(返回0)打印成功提示,如果下 載失敗,這再下載一次,如果還是失敗,就打印失敗
腳本如下
[[email protected] ~]# cat checkurl.sh #!/bin/bash CheckUrl(){ timeout=5 fails=0 success=0 while true do wget --timeout=$timeout --tries=1 http://www.baid1u.com -q -O /dev/null if [ $? -ne 0 ] then let fails=fails+1 else let success+=1 fi if [ $success -ge 1 ];then echo success exit 0 fi if [ $fails -ge 2 ];then echo fail exit 2 fi done } CheckUrl
測試,故意百度的網址寫錯
[[email protected] ~]# sh checkurl.sh fail
本文出自 “知識改變命運” 博客,請務必保留此出處http://ahtornado.blog.51cto.com/4826737/1928317
shell 實現監控Web服務狀態