1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
--- check_file_age.bak 2007-07-27 14:24:15.000000000 +0100
+++ check_file_age 2007-07-27 14:31:20.000000000 +0100
@@ -33,22 +33,23 @@
sub print_help ();
sub print_usage ();
-my ($opt_c, $opt_f, $opt_w, $opt_C, $opt_W, $opt_h, $opt_V);
-my ($result, $message, $age, $size, $st);
-
$PROGNAME="check_file_age";
-$opt_w = 240;
-$opt_c = 600;
-$opt_W = 0;
-$opt_C = 0;
-$opt_f = "";
+my $opt_V = undef;
+my $opt_w = 240;
+my $opt_c = 600;
+my $opt_W = 0;
+my $opt_C = 0;
+my $opt_f = "";
+my $opt_d = "";
+my $opt_h = "";
Getopt::Long::Configure('bundling');
GetOptions(
"V" => \$opt_V, "version" => \$opt_V,
"h" => \$opt_h, "help" => \$opt_h,
"f=s" => \$opt_f, "file" => \$opt_f,
+ "d=s" => \$opt_d, "dir" => \$opt_d,
"w=f" => \$opt_w, "warning-age=f" => \$opt_w,
"W=f" => \$opt_W, "warning-size=f" => \$opt_W,
"c=f" => \$opt_c, "critical-age=f" => \$opt_c,
@@ -64,25 +65,32 @@
exit $ERRORS{'OK'};
}
-$opt_f = shift unless ($opt_f);
+$opt_f = shift unless ($opt_f or $opt_d);
-if (! $opt_f) {
- print "No file specified\n";
+if (not $opt_f and not $opt_d) {
+ print "No file or directory specified\n";
exit $ERRORS{'UNKNOWN'};
}
# Examine the file.
-unless (-f $opt_f) {
+if ($opt_f and not -f $opt_f)
+{
print "$opt_f: File not found\n";
exit $ERRORS{'UNKNOWN'};
}
+elsif ($opt_d and not -d $opt_d)
+{
+ print "$opt_d: Directory not found\n";
+ exit $ERRORS{'UNKNOWN'};
+}
-$st = File::stat::stat($opt_f);
-$age = time - $st->mtime;
-$size = $st->size;
+my $file = $opt_f || $opt_d;
+my $st = File::stat::stat($file);
+my $age = time - $st->mtime;
+my $size = $st->size;
-$result = 'OK';
+my $result = 'OK';
if (($opt_c and $age > $opt_c) or ($opt_C and $size < $opt_C)) {
$result = 'CRITICAL';
@@ -91,7 +99,7 @@
$result = 'WARNING';
}
-print "$result - $opt_f is $age seconds old and $size bytes\n";
+print "$result - $file is $age seconds old and $size bytes\n";
exit $ERRORS{$result};
sub print_usage () {
|