Skip to content

Instantly share code, notes, and snippets.

@matlads
Created November 26, 2012 15:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matlads/4148694 to your computer and use it in GitHub Desktop.
Save matlads/4148694 to your computer and use it in GitHub Desktop.
Checking disk space using Filesys::Df with Email::Simple to email warnings.
#!/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