31 lines
604 B
Perl
Executable file
31 lines
604 B
Perl
Executable file
#!/usr/bin/perl -w
|
|
|
|
use strict;
|
|
use Getopt::Long qw(:config no_ignore_case);
|
|
|
|
sub usage() {
|
|
print "Usage: check_tftp -H <host> -f <file>\n";
|
|
}
|
|
|
|
my ($host, $file);
|
|
my $result = GetOptions(
|
|
"H|host=s" => \$host,
|
|
"f|file=s" => \$file,
|
|
);
|
|
|
|
if (!$host || !$file) {
|
|
usage();
|
|
exit(3);
|
|
}
|
|
|
|
$result = `echo -e 'timeout 1\nverbose\nget $file /dev/null' | tftp $host`;
|
|
my @splitted = split(/\n/, $result);
|
|
$result = $splitted[5];
|
|
|
|
if ($result =~ /Received \d+ bytes in [\d\.]+ seconds/) {
|
|
print "TFTP OK: $result";
|
|
exit(0);
|
|
} else {
|
|
print "TFTP CRITICAL: $result";
|
|
exit(2);
|
|
}
|