Hi people,
I've written a script that ping a mission-critical machine and if there is no response, it sends me a mail. I have scheduled that script in crontab to run every minute.
However, if the machine is down for some hours, the script will still send me a mail every minute, which I don't want!
I thought of exporting a custom env variable (machineup = n) when the machine is found offline (after sending the first and only mail), and for the second execution (before sending the mail), if machineup = n, it won't send the mail, until machineup = y.
I have been told that exporting system env variables isn't possible with Perl. I could only export env variables for the current and child processes.
Is there any way I can do this? Any ideas?
Here is my code :
Thanks in advance for your suggestions,
Steve
I've written a script that ping a mission-critical machine and if there is no response, it sends me a mail. I have scheduled that script in crontab to run every minute.
However, if the machine is down for some hours, the script will still send me a mail every minute, which I don't want!
I thought of exporting a custom env variable (machineup = n) when the machine is found offline (after sending the first and only mail), and for the second execution (before sending the mail), if machineup = n, it won't send the mail, until machineup = y.
I have been told that exporting system env variables isn't possible with Perl. I could only export env variables for the current and child processes.
Is there any way I can do this? Any ideas?
Here is my code :
Code:
#!/usr/bin/perl
#
# basemon.pl
#
# Monitoring program
use strict;
use warnings;
use Mail::Sendmail;
use Net::Ping;
my $host = "172.17.3.5";
my $p = Net::Ping->new();
if (!($p->ping($host,5))) {
my %mail = ( To => 'me@here.com',
From => "$ENV{HOSTNAME}\@smurfit.com",
Subject => 'ALERT : Base is down!',
Message => " Base is down ..."
);
sendmail(%mail) or die $Mail::Sendmail::error;
}
$p->close();
Thanks in advance for your suggestions,
Steve