You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Princeton/pu/libexec/check_file.pl

49 lines
654 B
Perl

#!/usr/bin/perl
use Getopt::Std;
use File::Basename;
getopts('wch');
if ($opt_h or $ARGV[0] eq '') {
print "Usage:\n";
print " check_file -w|-c file1,file2,file3,...\n";
print " check_file -h\n";
exit 0;
}
(@files) = split(/,/, $ARGV[0]);
foreach $f (@files) {
($n, $p, $s) = fileparse($f, ());
$ff = "$n$s";
@st = stat $f;
if ($st[7] eq '') {
$bad = $bad . " $ff(?)";
}
elsif ($st[7] == 0) {
$bad = $bad . " $ff(0)";
}
else {
$ok = $ok . " $ff";
}
}
if ($bad ne '') {
if ($opt_w) {
print "FILES WARNING:$bad\n";
exit 1;
}
if ($opt_c) {
print "FILES CRITICAL:$bad\n";
exit 2;
}
}
print "FILES OK:$ok\n";
exit 0;