_ Monitoring script HTTP server status

! # bin / bash
# function: monitoring HTTP server status (test return code)
# Author: liusingbon
# set variables, URL goal for your website url to be detected (IP or domain name)
url = HTTP: //192.168.2.1 /index.html
#-defined functions check_http
# http server using the curl command to check the status of
# -m set curl access regardless of success or failure, the time of maximum consumption is 5 seconds, 5 seconds is connected to the corresponding service is considered not connect
# -s setting silent connection, connection speed connection is not displayed, time consumption information
# -o export the contents of the page curl to download to / dev / null (the default page content will appear on the screen)
# set the -w content curl command to be displayed % {http_code}, the server specifies status code returned curl
function check_http {
         status_code = $ (-s -o curl. 5 -m / dev / null% -w} {$ HTTP_CODE URL)
            }
the while:
do
    check_http
    DATE = $ (DATE the Y m%%% + D-% H:% m:% S)
     # generates an alarm message content
    echo "the current time is: $ DATE
    $ server URL abnormal status code $ {status_code}.
     Please investigation as soon as possible abnormal "> /tmp/http$$.pid
     function test server # specify the state, according to the return code and decide whether to send alarm messages or information written to the log normal
    IF [$ status_code -ne 200]; the then
        mail - Warning the root S </tmp/http$$.pid
    the else
        echo "$ URL connection is normal" >> /var/log/http.log
    Fi
    SLEEP. 5
DONE

Guess you like

Origin www.cnblogs.com/liusingbon/p/11099570.html