I'm looking for input on the code itself and formatting/style. This script parses the output of df -h
on a Linux server and emails the user if the usage percentage is above the threshold (90% in this case).
#!/usr/bin/perl
use warnings;
use strict;
use Mail::Sendmail;
my $svr = `hostname`;
my @output = `df -h`;
my $msg;
my $mailto = '[email protected]';
my $threshold = 90;
sub main
{
foreach (@output) {
if (($_ =~ m/(\d+)% (.*)/) && ( $1 > $threshold )) {
chomp($svr); $msg = "$svr: $2 volume is $1 percent full\n" }
}
my %mail = ( To => $mailto,
From => '[email protected]',
Subject => "$svr has a full file system",
Message => $msg
);
if ( defined $msg ) {
sendmail(%mail) or die $Mail::Sendmail::error;
}
}
main