#!/usr/bin/perl ################################################################################ # # File: $RCSfile: diskspace,v $ # Revision: $Revision: 1.2 $ # Description: Check filesystems to see if they are becoming too full # Author: Andrew@DeFaria.com # Created: Fri Mar 12 10:17:44 PST 2004 # Modified: $Date: 2010/06/08 15:03:27 $ # Language: Perl # # (c) Copyright 2005, ClearSCM, Inc., all rights reserved # ################################################################################ use strict; use warnings; use File::Spec; use FindBin; use lib "$FindBin::Bin/../lib"; use Display; my $threshold = 90; sub Usage { my $msg = shift; display "ERROR: $msg\n" if defined $msg; display "diskspace\t[-v] [-d] [-u] [ -t ]"; display "\t-v\tTurn on verbose mode"; display "\t-d\tTurn on debug mode"; display "\t-u\tThis usage message"; display "\t-t\tThreshold (0-100)"; exit 1; } # Usage sub CheckLocalFilesystems { my @local_filesystems = `df -lP`; @local_filesystems = grep {/^\/dev/} @local_filesystems; foreach (@local_filesystems) { my ($fs, $blocks, $used, $available, $used_percent, $mounted_on) = split; if ($used_percent =~ /(\d+)%/) { $used_percent = $1; } # if $available = sprintf ("%.3f", $available / 1024); # Check if over threshold and report if ($used_percent <= $threshold ) { verbose "$mounted_on is $used_percent% full - $available Megs left"; } else { warning "$mounted_on is $used_percent% full - $available Megs left"; } # if } # foreach } # CheckLocalFilesystems # Get parameters while ($ARGV [0]) { if ($ARGV [0] eq "-v") { set_verbose; } elsif ($ARGV [0] eq "-d") { set_debug; } elsif ($ARGV [0] eq "-t") { shift (@ARGV); if (!$ARGV [0]) { Usage "Must specify threshold after -t"; } else { $threshold = $ARGV [0]; } # if } elsif ($ARGV [0] eq "-u") { Usage; } else { Usage "Unknown argument found: " . $ARGV [0]; } # if shift (@ARGV); } # while verbose "Theshold: $threshold\%"; CheckLocalFilesystems;