2 ################################################################################
5 # Description: Check filesystems to see if they are becoming too full
6 # Author: Andrew@DeFaria.com
7 # Created: Fri Mar 12 10:17:44 PST 2004
11 # (c) Copyright 2004, Andrew@DeFaria.com, all rights reserved
13 ################################################################################
18 my ($me, $abs_path, $lib_path, $bin_path, $log_path);
21 # Extract relative path and basename from script name.
22 $0 =~ /(.*)[\/\\](.*)/;
24 $abs_path = (!defined $1) ? "." : File::Spec->rel2abs ($1);
25 $me = (!defined $2) ? $0 : $2;
28 $bin_path = "$abs_path";
29 $lib_path = "$abs_path/../../lib";
30 $log_path = "$abs_path/../../log";
32 # Add the appropriate path to our modules to @INC array.
33 unshift (@INC, "$lib_path");
43 display "ERROR: $msg\n" if defined $msg;
45 display "$me\t[-v] [-d] [-u] [ -n | -l ]";
46 display "\t-v\tTurn on verbose mode";
47 display "\t-d\tTurn on debug mode";
48 display "\t-u\tThis usage message";
49 display "\t-t\tThreshold (0-100)";
54 sub CheckFilesystemSpace {
55 my $filesystem = shift;
57 # Isolate the disk usage line
58 my @diskusage = `df -k $filesystem`;
62 my ($fs, $blocks, $used, $available, $used_percent, $mounted_on) = split;
64 if ($used_percent =~ /(\d+)%/) {
68 $available = sprintf ("%.3f", $available / 1024);
70 # Check if over threshold and report
71 if ($used_percent <= $threshold ) {
72 verbose "$mounted_on is $used_percent% full - $available Megs left";
74 warning "$mounted_on is $used_percent% full - $available Megs left";
76 } # CheckFilesystemSpace
78 sub CheckLocalFilesystems {
79 my @local_filesystems = `df -k`;
81 @local_filesystems = grep {/^\/dev/} @local_filesystems;
83 foreach (@local_filesystems) {
84 my ($fs, $blocks, $used, $available, $used_percent, $mounted_on) = split;
85 CheckFilesystemSpace $mounted_on;
87 } # CheckLocalFilesystems
91 if ($ARGV [0] eq "-v") {
93 } elsif ($ARGV [0] eq "-d") {
95 } elsif ($ARGV [0] eq "-t") {
98 Usage "Must specify threshold after -t";
100 $threshold = $ARGV [0];
102 } elsif ($ARGV [0] eq "-u") {
105 Usage "Unknown argument found: " . $ARGV [0];
111 debug "Theshold: $threshold";
112 CheckLocalFilesystems;