Shell implements monitoring Web service status

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.