#!/usr/bin/perl use Mail::Sendmail; use strict; my $from_email = 'Server Status /dev/null") == 0 or die<<'EOF'; You need to install the timeout script, available from http://www.oase-shareware.org/shell/scripts/quickies/timeout EOF } # ---------------------------------------------------------------------------- sub Check_Ping { my $stderr; my $status = `ping -c 2 -w $timeout $server 2>$tempfile`; if (-s $tempfile) { open ERR,$tempfile; $stderr = join '', ; close ERR; } my $message; if ($status !~ /0\% packet loss/) { $message .= "The server is not responding to ping.\n\n"; $message .= "Here is the status returned by ping:\n$status\n\n" if $status ne ''; $message .= "Here is a message printed to STDERR by ping:\n$stderr\n\n" if $stderr ne ''; } unlink $tempfile; return $message; } # ---------------------------------------------------------------------------- sub Check_DB { my $stderr; # Sigh. mysqladmin -t doesn't seem to work. Use the timeout script from # http://www.oase-shareware.org/shell/scripts/quickies/timeout my $status = `$timeout_cmd -t $timeout mysqladmin -h $server -u $db_user status 2>$tempfile`; if (-s $tempfile) { open ERR,$tempfile; $stderr = join '', ; close ERR; } my $message; if ($status !~ /Uptime/) { $message .= "The database is not responding.\n\n"; $message .= "It appears that the mysqladmin command timed out.\n\n" if $status eq '' && $stderr eq ''; $message .= "Here is the status returned by mysqladmin:\n$status\n\n" if $status ne ''; $message .= "Here is a message printed to STDERR by mysqladmin:\n$stderr\n\n" if $stderr ne ''; } unlink $tempfile; return $message; } # ---------------------------------------------------------------------------- sub Check_CGI { my $stderr; my $status = `lynx -source 'http://handlers.newsclipper.com/cgi-bin/checkversion?tag=date&ncversion=1.18&debug=0'`; if (-s $tempfile) { open ERR,$tempfile; $stderr = join '', ; close ERR; } my $message; if ($status !~ /\d\.\d/) { $message .= "checkversion for handler date is not working.\n\n"; $message .= "Here is the status returned by the fetch:\n$status\n\n" if $status ne ''; $message .= "Here is a message printed to STDERR by lynx:\n$stderr\n\n" if $stderr ne ''; } unlink $tempfile; return $message; } # ---------------------------------------------------------------------------- sub Send_Email { my $from_email = shift; my $to_email = shift; my $message = shift; my %mail = ( To => $to_email, From => $from_email, Message => $message, Subject => "Server is having problems!", ); sendmail(%mail) or die $Mail::Sendmail::error; } # ---------------------------------------------------------------------------- END { unlink $tempfile; }