#!/usr/bin/perl -w # # check_df # # AUTHOR: # Dan Harkless # # COPYRIGHT: # This file is Copyright (C) 2005 by Dan Harkless, and is released under the # GNU General Public License . # # USAGE: # % check_df [] [] # # EXAMPLE: # % check_df -H 99 # # DESCRIPTION: # A script you can call from 'cron' to output (and thus email) a 'df' listing # if any of the filesystems' usage is greater than or equal to the percentage # you specify on the commandline. If no percentage is specified, '95' is # assumed. # # Any option strings (beginning with '-') will be passed along to df. # # DATE MODIFICATION # ========== ================================================================== # 2005-08-01 Added ability to pass options to df and removed default use of -k. # 2004-11-17 Original. $percentage = 95; while (scalar @ARGV > 0) { $option = shift; if ($option =~ /^-/) { push @df_options, $option; } else { $percentage = $option; } } open(DF, "df @df_options|") or die; use vars qw($header_line); $header_line = ; push @df_output, $header_line; while () { push @df_output, $_; if (/(\d{1,3})%/) { if ($1 >= $percentage) { $at_or_above_percentage = 1; } } } close DF; if ($at_or_above_percentage) { print @df_output; }