Recently a friend of mine asked me something to periodically monitor the Disk Usage of
a Linux Server...
Well, actually I'm not doing System Administration, and there are a lot of tools/script
out there on the Internet which can do the work for you, but..
true Engineers can't resist in 'Reinventig the wheel' :-)
This is a part of a Script which I wrote some years ago... surely It's something that
should need a good refactoring for a more general usage, but It can give you an idea
of what to do....
Yes, It's the famous 'write-only' Perl... It needs no libraries... to use it like a daemon
you just have to make some modifications to the code and put it in your crontab file...
enjoy it! :-)
#SendMail (pass Problem Kind and Value)
open (MAIL,"|/usr/sbin/sendmail -t");
print MAIL "To: youremail\@youremail\n";
print MAIL "Subject: ALERT ALERT!\n";
print MAIL $Problem . ": " . $Value . "\n";
#Query Disk Space (pass Disk number)
my @Disk=`df -t ext3 -l`;
my $line, $Available;
DISKSCAN: foreach $line (@Disk)
$line =~ /(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/;
last DISKSCAN if($DiskCounter==$DiskNumber);
#Scan for Disk ALERT
my $DiskAlert="Disk Alert";