#!/usr/bin/perl use strict; # Edit these three lines my @filesystems = ('/','/home','/storage','/var'); my $maxpercent = '95'; my $email = 'user@domain.com'; # Don't edit below here! my @message; my $machinename = `uname -n`; chomp $machinename; my @df = `df`; foreach my $line (@df) { chomp $line; foreach my $fs (@filesystems) { if ($line =~ /$fs$/) { my ($percent,$foo) = split ('%',$line); my $percent = substr ($percent, 52, 55); if ($percent > $maxpercent) { my $messageline = $fs . " is at " . $percent . "%"; @message = (@message,$messageline); } } } } # TO DEBUG UNHASH THE FOLLOWING TWO LINES. I suggest this to test it first! #foreach my $msgline (@message) { print "$msgline\n"; } #exit; if (@message) { open(MAIL, "|/usr/sbin/sendmail -t -oi -oem") || print "Error sending email\n"; print MAIL "To: $email\n"; print MAIL "From: diskspace\@$machinename\n"; print MAIL "Subject: Low disk space warning\n\n"; foreach my $msgline (@message) { print MAIL "$msgline\n"; } close(MAIL); }