A simple web site status monitoring script

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

A very simple Perl script to enable one to monitor one's own site to
see if it is down/unavailable.

The script just reads the page header, and as such doesn't download
much data.

I put in a five minute delay via the sleep 600; You might change that
to what ever is more convenient to you.

I am only checking for status codes commencing with a "5", which are
returned when a server is unavailable (routing issues for example),
among other times. Again, you may wish to expand on this.

Under Windows the following script runs until ctrl-break is pressed.


use LWP::UserAgent;
use HTTP::Response

# The url you wish to test
$url = "http://www.example.com ";

    $ua = LWP::UserAgent->new;

    my $response = $ua->get($url);

    $status = $response->status_line;

    # printf "%s\n",$response->status_line;

    ($sec, $min, $hour, $monthday, $month, $year, $weekday, $yearday,
$isdaylight) = gmtime;
    $year += 1900;
    $month += 1;

    # Status codes commencing with a 5 indicate a server problem; 4 a
client problem (including page not found); 2 everything is okay.

    if (substr($status,0,1) eq "5")
        print " $monthday/$month/$year $hour:$min Server is
        sleep 600;
        print "$monthday/$month/$year $hour:$min Server is okay\n";
        sleep 600;

This is a quick and efficient system offered as is, don't bother
flaming me, use it if you like, don't if you don't.


Site Timeline