Monitoring Web Service status using the shell
Principle: Download the website and write the output to/dev/null if the command executes successfully (returns 0) Print success prompt, if the download fails, this is downloaded again, if it fails, the print fails
The script is as follows
[[Email protected] ~]# cat checkurl.sh #!/bin/bashcheckurl () {timeout=5fails=0success= 0while 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 &nbSp;fidone}checkurl
Test, intentionally Baidu's URL is wrong
[[Email protected] ~]# sh checkurl.sh fail
This article is from the "Knowledge Change Destiny" blog, please be sure to keep this source http://ahtornado.blog.51cto.com/4826737/1928317
Shell implements monitoring Web service status