Lhamo Latso has asked for the wisdom of the Perl Monks concerning the following question:
I have written a crontab Perl program to check whether the company website is available for the customers. We would like to know if there is a problem before the users call to report it.
My code is running on Perl 5.6.1 under RedHat Linux AS v2.1. I am using lwp-request to hit the website.
I am finding that the response time varies at certain times of the day and my timeout causes false failures. I have increased the timeout, but I would like to capture the HTTP error code and know whether it is a timeout or something else.
Here is the code. Thanks in advance!
#!/usr/bin/perl -w # /usr/local/bin/webalert.pl [mail address] [web address] use strict; use LWP; local *MAIL; # get the mail address if there is one. my $mailaddr = shift @ARGV; # get the web address if there is one. my $webaddr = (shift @ARGV ||"www.perlmonks.org"); my $timeout = 15; if (system "/usr/bin/lwp-request -t $timeout $webaddr >/dev/null 2>&1" +) { sendmail_or_print() } sub sendmail_or_print { # get the mail address if there is one. my $hostname = "from ". (`hostname 2>/dev/null` ||"who"); # get the mail address if there is one. if ($mailaddr) { open MAIL, "|mail -s \"Web Alert $hostname\" $mailaddr"; } else { open MAIL, ">&STDOUT"; } print MAIL "\n\n$webaddr NOT available: " . localtime() ."\n\n"; print MAIL "$timeout second timeout used.\n\n"; close MAIL; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: website availability ping
by Roy Johnson (Monsignor) on Oct 28, 2003 at 19:34 UTC | |
|
Re: website availability ping
by pg (Canon) on Oct 28, 2003 at 19:38 UTC | |
|
Re: website availability ping
by diakonos (Hermit) on Oct 28, 2003 at 19:04 UTC | |
by pg (Canon) on Oct 28, 2003 at 19:31 UTC | |
by diakonos (Hermit) on Oct 28, 2003 at 20:22 UTC | |
by Lhamo Latso (Scribe) on Oct 29, 2003 at 06:23 UTC | |
|
Re: website availability ping
by TVSET (Chaplain) on Oct 29, 2003 at 02:57 UTC | |
|
Re: website availability ping
by jacques (Priest) on Oct 29, 2003 at 02:26 UTC |