Преглед изворни кода

check_file_age: does not handle filenames WITHOUT space!

Fix for issue #213

perl apparently handles `glob` differently on different systems.
For a previous problem,"check_file_age: does not handle filenames with space"
I added double-quote marks around the incoming filename before
calling `glob`. That fixed finding files with spaces in the name on
all systems. But if the filename did NOT have a space, it broke on
some systems, but not on others.

openSUSE 13.2:
$ ./check_file_age -w 1000 -c 1500 "foo bar"
DEBUG: filename is |foo bar|
FILE_AGE CRITICAL: foo is 2319 seconds old and 91 bytes  | age=2323s;90;100 size=91B;0;0;0
$ ./check_file_age -w 1000 -c 1500 foo
DEBUG: filename is |foo|
FILE_AGE CRITICAL: foo is 2323 seconds old and 91 bytes  | age=2323s;90;100 size=91B;0;0;0

CentOS 6.7:
$ ./check_file_age -w 1000 -c 1500 "foo bar"
DEBUG: filename is |foo bar|
FILE_AGE CRITICAL: foo is 1651 seconds old and 91 bytes  | age=2323s;90;100 size=91B;0;0;0
$ ./check_file_age -w 1000 -c 1500 foo
DEBUG: filename is |"foo"|
FILE_AGE CRITICAL: File not found - "foo"

So my change is to wrap the filename in double-quotes only if it
contains spaces. That appears to have fixed the problem.
John C. Frickson пре 9 година
родитељ
комит
367a44187d
2 измењених фајлова са 2 додато и 1 уклоњено
  1. 1 0
      NEWS
  2. 1 1
      plugins-scripts/check_file_age.pl

+ 1 - 0
NEWS

@@ -25,6 +25,7 @@ This file documents the major additions and syntax changes between releases.
 	check_ntp: touch ntp servers at most once every seconds
 	check_dns: authoritative test (-A) is broken
 	check_dns: reports TXT records incorrectly
+	check_file_age: does not handle filenames WITHOUT space!
 
 
 2.1.4 2016-11-17

+ 1 - 1
plugins-scripts/check_file_age.pl

@@ -77,7 +77,7 @@ if (! $opt_f) {
 	exit $ERRORS{'UNKNOWN'};
 }
 
-$opt_f = '"' . $opt_f . '"';
+$opt_f = '"' . $opt_f . '"' if $opt_f =~ / /;
 
 # Check that file(s) exists (can be directory or link)
 $perfdata = "";