#!/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;

