[nagios-plugins] utils.sh: Don't define $ECHO

Git Repository git at nagios-plugins.org
Mon Jan 13 23:00:09 CET 2014


 Module: nagios-plugins
 Branch: master
 Commit: 9db763963f3993f923619a2147e4313b09f12134
 Author: Holger Weiss <holger at zedat.fu-berlin.de>
   Date: Mon Jan 13 22:55:43 2014 +0100
    URL: https://www.nagios-plugins.org/repositories/nagios-plugins/commit/?id=9db7639

utils.sh: Don't define $ECHO

In utils.sh, $ECHO was set to printf(1) or echo(1), depending on whether
printf(1) is available in /usr/bin.  This resulted in various bugs, as
printf(1) cannot be used in the same way as echo(1).

Thanks to Trevor Hemsley for reporting one of those bugs: If $ECHO was
set to printf(1), check_log stumbled when reporting a log line with a
"%" character.

---

 NEWS                         |  1 +
 plugins-scripts/check_log.sh | 11 +++++------
 plugins-scripts/utils.sh.in  | 10 ++--------
 3 files changed, 8 insertions(+), 14 deletions(-)

diff --git a/NEWS b/NEWS
index 5f88ff5..d7fe8f3 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ This file documents the major additions and syntax changes between releases.
 1.6 ...
 	WARNINGS
 	check_procs now ignores its parent process to avoid unexpected results when invoked via certain shells
+	utils.sh no longer defines ECHO
 
 1.5 2nd October 2013
 	ENHANCEMENTS
diff --git a/plugins-scripts/check_log.sh b/plugins-scripts/check_log.sh
index a1bfb48..ca5810a 100755
--- a/plugins-scripts/check_log.sh
+++ b/plugins-scripts/check_log.sh
@@ -60,7 +60,6 @@
 # TV: removed PATH restriction. Need to think more about what this means overall
 #PATH=""
 
-ECHO="/bin/echo"
 GREP="/bin/egrep"
 DIFF="/bin/diff"
 TAIL="/bin/tail"
@@ -167,10 +166,10 @@ done
 # If the source log file doesn't exist, exit
 
 if [ ! -e $logfile ]; then
-    $ECHO "Log check error: Log file $logfile does not exist!\n"
+    echo "Log check error: Log file $logfile does not exist!"
     exit $STATE_UNKNOWN
 elif [ ! -r $logfile ] ; then
-    $ECHO "Log check error: Log file $logfile is not readable!\n"
+    echo "Log check error: Log file $logfile is not readable!"
     exit $STATE_UNKNOWN
 fi
 
@@ -180,7 +179,7 @@ fi
 
 if [ ! -e $oldlog ]; then
     $CAT $logfile > $oldlog
-    $ECHO "Log check data initialized...\n"
+    echo "Log check data initialized..."
     exit $STATE_OK
 fi
 
@@ -209,10 +208,10 @@ $RM -f $tempdiff
 $CAT $logfile > $oldlog
 
 if [ "$count" = "0" ]; then # no matches, exit with no error
-    $ECHO "Log check ok - 0 pattern matches found\n"
+    echo "Log check ok - 0 pattern matches found"
     exitstatus=$STATE_OK
 else # Print total matche count and the last entry we found
-    $ECHO "($count) $lastentry"
+    echo "($count) $lastentry"
     exitstatus=$STATE_CRITICAL
 fi
 
diff --git a/plugins-scripts/utils.sh.in b/plugins-scripts/utils.sh.in
index 4a07df8..031c035 100644
--- a/plugins-scripts/utils.sh.in
+++ b/plugins-scripts/utils.sh.in
@@ -6,19 +6,13 @@ STATE_CRITICAL=2
 STATE_UNKNOWN=3
 STATE_DEPENDENT=4
 
-if test -x /usr/bin/printf; then
-	ECHO=/usr/bin/printf
-else
-	ECHO=echo
-fi
-
 print_revision() {
 	echo "$1 v$2 (@PACKAGE@ @VERSION@)"
-	$ECHO "@WARRANTY@" | sed -e 's/\n/ /g'
+	printf '%b' "@WARRANTY@"
 }
 
 support() {
-	$ECHO "@SUPPORT@" | sed -e 's/\n/ /g'
+	printf '%b' "@SUPPORT@"
 }
 
 #




More information about the Commits mailing list