#!/usr/bin/perl # # Sorry for the simplicity of this script, but as a first submission... # # Emails/Pages me when a filesystem > 90% full # # always use strict use strict; # make a variable to easily change some behavior my($warn_percentage) = 90; # predeclare our variables (not necessary, but probably a good idea) my(%df); # df hash that holds all our information my($host); # hostname # Rather than 3 backticks for df, just do it once and parse it with perl! # Also, make $fs into an array instead of string then split to array # Finally, we don't really need $full, since that's just grep /100/,@fs #$df=`df -lk 2>/dev/null`; #$fs=`df -lk 2>/dev/null | grep -v used | cut -d'%' -f2 | grep -v denied`; #$full=`df -lk 2>/dev/null | grep -v used | cut -d'%' -f1`; foreach (`df -lk 2>/dev/null`) { if (/(\b\d+)%\s+(\S+)$/) { $df{$2} = $1; } } # removed some string manipulation that isn't needed any longer #$full =~ s/.*(..\d)$/\1/mg; #$fs=~s/\s+/ /g; #$full=~s/\s+/ /g; #@fs=split(" ",$fs); #@full=split(" ",$full); # We can combine this into one statement #$host=`hostname`; #chomp($host); chomp($host = `hostname`); # this loop changes somewhat #$fs=@fs; #chomp($date); # where is $date coming from? # note that the mailx stuff isn't tested, as I don't have mailx on my system foreach (keys %df) { if ($df{$_} > $warn_percentage) { print "Host: $host Filesystem: $_ is $df{$_}% full!\n"; system("mailx -s \"$host:$_ is $df{$_}%\" youremail\@host.com << /dev/null"); } } #while ($fs) { # $fs=shift(@fs); # $full=shift(@full); # chomp($fs); # chomp($full); # if ($full > 90) { # print "Host: $host Filesystem: $fs is ${full}% full!\n"; # @chk=grep(/$fs:$full/,@log); # not sure what all this log stuff is... # undef(@log); # $chk=@chk; # close(LOG); # } # if ($chk == 0) { # `mailx -s "$host:$fs is ${full}%" youremail\@host.com <