Created
November 26, 2012 15:08
-
-
Save matlads/4148694 to your computer and use it in GitHub Desktop.
Checking disk space using Filesys::Df with Email::Simple to email warnings.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Filesys::Df; | |
use Email::Simple; | |
use Email::Sender::Simple qw(sendmail); | |
my $warn_limit = 75; | |
my @mount_points = qw( / /tmp ); | |
my $email_from = 'sysadmin@example.com'; | |
my $email_to = 'interested@example.com'; | |
my @messages; | |
for my $mount_point ( @mount_points ) { | |
my $df_ref = df( $mount_point ); | |
my $message; | |
if ($df_ref) { | |
if ( $df_ref->{per} > $warn_limit ) { | |
push @messages, | |
"No Space on $mount_point [ $df_ref->{per}% full ]"; | |
} | |
} | |
} | |
if (@messages) { | |
my $email_body = join "\n", @messages; | |
my $email = Email::Simple->create( | |
header => [ | |
From => $email_from, | |
To => $email_to, | |
Subject => 'Disk space report', | |
], | |
body => $email_body, | |
); | |
sendmail($email); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment