Perl Low Disk Space Warning Cron Script

This is a quick little script I wrote to warn me when disk space is getting low on a server I’m responsible for.

i just stuck this into a daily cron and now I know when to act!

use strict;
use Filesys::DiskFree;

# init
my $sendmail = "/usr/lib/sendmail -t";

# file system to monitor
my $dirFilesystem = "/";
my $systemName = "putYourSystemNameHere";

# low diskspace warning threshhold
my $warningThreshhold=20 ; # in percent

# fs disk freespace
my $fsHandle = new Filesys::DiskFree;
my $fsSpaceAvail = $fsHandle->;avail($dirFilesystem);
my $fsSpaceTotal = $fsHandle->;total($dirFilesystem);
my $fsSpaceUsed = $fsHandle->;used($dirFilesystem);
my $fsSpaceAvailPct = (($fsSpaceAvail) / ($fsSpaceAvail+$fsSpaceUsed)) * 100.0;

# email setup
my $emailTo='';
my $emailFrom='';
my $emailSubject="WARNING Low Disk Space for: $systemName";
my $emailBody = sprintf("WARNING Low Disk Space on '$systemName $dirFilesystem': %0.2f%%\n", $fsSpaceAvailPct);

# If free space is below threshhold, e-mail a warning message.
if ($fsSpaceAvailPct < $warningThreshhold) {
        open(MAIL, "|$sendmail");
        print MAIL "To: $emailTo\n";
        print MAIL "From: $emailFrom\n";
        print MAIL "Subject: $emailSubject\n";
        print MAIL $emailBody;
Be Sociable, Share!

One thought on “Perl Low Disk Space Warning Cron Script

  1. I need the perl script which stream video from server to any mobile device which contains that particular format please mail me a sample code for streaming a video on PC please email to ever you have code for streaming please share with me. Thanks, prasad

Comments are closed.