Category: | Utility Scripts |
Author/Contact Info | rob_au |
Description: | This little script is a rewrite of a very nasty bash script that for a long time formed a core crontab entry on systems which I administer. This code allows for the alerting of the system administrator via email when the disk space on any of the mounted partitions drops below a set threshold. The corresponding template file used for the email sent to the system administrator may look similar to the following:
|
#!/usr/bin/perl -Tw
use constant EMAIL => 'robau@cpan.org';
use constant SERVER => 'localhost';
use constant ALERT => 90;
use constant FILESYS => ( '/', '/usr', '/var', '/home' );
use Carp;
use Filesys::Df ();
use Mail::Mailer;
use Template;
use strict;
my @alert = ();
foreach my $fs ( FILESYS ) {
my $ref = Filesys::Df::df( $fs );
push @alert, {
'mountpoint' => $fs,
'percent' => $ref->{'per'},
'blocks_free' => $ref->{'bfree'},
'blocks_used' => $ref->{'used'},
'blocks_total' => $ref->{'blocks'}
} if $ref->{'per'} > ALERT;
}
if (scalar @alert) {
my $output;
my $mail = Mail::Mailer->new( 'smtp', Server => SERVER );
$mail->open({
'To' => EMAIL,
'From' => EMAIL
});
my $template = Template->new({ 'ABSOLUTE' => 1 });
$template->process(
'/isp/var/mail/dfmon-alert.tt2',
{ 'filesystems' => \@alert },
\$output
) || croak( 'Error in processing mail template - ', $template->err
+or );
print $mail $output;
$mail->close;
}
exit 0;
|
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: dfmon - Disk Free Monitor
by neilwatson (Priest) on May 13, 2002 at 15:24 UTC | |
by rob_au (Abbot) on May 14, 2002 at 06:30 UTC | |
by neilwatson (Priest) on May 14, 2002 at 12:55 UTC |