#!/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; }