3 # (c)2001 Patrick Greenwell, Stealthgeeks, LLC. (patrick@stealthgeeks.net)
4 # Licensed under the GNU GPL
5 # http://www.gnu.org/licenses/gpl.html
7 # check_backup: Checks a directory to see if at least one file was
8 # created within a specified period of time that is of equal to or greater
12 # Last Updated: 9/12/01
16 if ($0 =~ m/^(.*?)[\/\\]([^\
/\\]+)$/) {
25 use vars
qw($opt_H $opt_d $opt_s $opt_t $verbose $PROGNAME);
26 use lib $main::runtimedir;
27 use utils qw($TIMEOUT %ERRORS &print_revision &usage &support &is_error);
34 my ($filesize, $answer) = ();
35 my $state = $ERRORS{'UNKNOWN'};
40 # Time period(in seconds)
43 # Minimum size of file (in bytes)
44 my $minsize = "40000000";
46 delete @ENV{'PATH', 'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
48 Getopt::Long::Configure('bundling', 'no_ignore_case');
50 ("V|version" => \&version,
52 "v|verbose" => \$verbose,
53 "d|directory=s" => \$opt_d,
54 "s|minsize=s" => \$opt_s,
55 "t|timeout=s" => \$opt_t,
58 ($opt_s) || ($opt_s = shift) || usage("Minimum File size not specified\n");
59 usage("File size must be numeric value") unless ($opt_s =~ m/^[0-9]+$/);
61 (($opt_t) && ($TIMEOUT = $opt_t)) || ($TIMEOUT = 120);
62 usage("TIMEOUT must be numeric value") unless ($TIMEOUT =~ m/^[0-9]+$/);
64 # Don't hang if there are timeout issues
66 print ("ERROR: No response from ftp server (alarm)\n");
67 exit $ERRORS{'UNKNOWN'};
75 opendir(THISDIR, "$dir") or die "Can't open directory! $!";
76 my @allfiles = grep !/^\./, readdir THISDIR;
78 while (my $file = $dir . pop @allfiles){
79 my ($size, $mtime) = (stat($file))[7,9];
80 if (((my $a = ($time - $mtime)) <= $within) and ($size >= $opt_s)){
81 display_res("OK: File $file is <= $within and >=$opt_s bytes.\n","OK");
85 # If we got here nothing matched....
86 display_res("CRITICAL: No files in $dir are <= $within and >= $minsize.", "CRITICAL");
91 print "Usage: $PROGNAME -s <minimum file size in bytes> -t <timeout> \n";
95 print_revision($PROGNAME,'$ Revision: 1.0 $ ');
101 print_revision($PROGNAME,'$ Revision: 1.0 $ ');
110 sub display_res ($$) {
111 my ($answer, $state) = @_;
113 exit $ERRORS{$state};