Code

check_host: Allocate a large-enough buffer for the host table.
[nagiosplug.git] / plugins-scripts / check_log.sh
index 355bd01e3251318d0605b59331ea932169a596fc..a1bfb486c7afa021f5d374de30d8e5cf8bcf4b23 100755 (executable)
 
 # Paths to commands used in this script.  These
 # may have to be modified to match your system setup.
-
-PATH=""
+# TV: removed PATH restriction. Need to think more about what this means overall
+#PATH=""
 
 ECHO="/bin/echo"
-GREP="/bin/grep"
+GREP="/bin/egrep"
 DIFF="/bin/diff"
 TAIL="/bin/tail"
 CAT="/bin/cat"
 RM="/bin/rm"
+CHMOD="/bin/chmod"
+TOUCH="/bin/touch"
 
 PROGNAME=`/bin/basename $0`
-PROGPATH=`echo $0 | /bin/sed -e 's,[\\/][^\\/][^\\/]*$,,'`
-REVISION=`echo '$Revision$' | /bin/sed -e 's/[^0-9.]//g'`
+PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
+REVISION="@NP_VERSION@"
 
 . $PROGPATH/utils.sh
 
@@ -114,11 +116,11 @@ while test -n "$1"; do
             exit $STATE_OK
             ;;
         --version)
-            print_revision $PROGNAME $VERSION
+            print_revision $PROGNAME $REVISION
             exit $STATE_OK
             ;;
         -V)
-            print_revision $PROGNAME $VERSION
+            print_revision $PROGNAME $REVISION
             exit $STATE_OK
             ;;
         --filename)
@@ -167,6 +169,9 @@ done
 if [ ! -e $logfile ]; then
     $ECHO "Log check error: Log file $logfile does not exist!\n"
     exit $STATE_UNKNOWN
+elif [ ! -r $logfile ] ; then
+    $ECHO "Log check error: Log file $logfile is not readable!\n"
+    exit $STATE_UNKNOWN
 fi
 
 # If the old log file doesn't exist, this must be the first time
@@ -188,17 +193,17 @@ if [ -x /bin/mktemp ]; then
 else
     tempdiff=`/bin/date '+%H%M%S'`
     tempdiff="/tmp/check_log.${tempdiff}"
-    /bin/touch $tempdiff
-    chmod 600 $tempdiff
+    $TOUCH $tempdiff
+    $CHMOD 600 $tempdiff
 fi
 
-$DIFF $logfile $oldlog > $tempdiff
+$DIFF $logfile $oldlog | $GREP -v "^>" > $tempdiff
 
 # Count the number of matching log entries we have
 count=`$GREP -c "$query" $tempdiff`
 
 # Get the last matching entry in the diff file
-lastentry=`$GREP "$query" $tempdiff | $TAIL --lines=1`
+lastentry=`$GREP "$query" $tempdiff | $TAIL -1`
 
 $RM -f $tempdiff
 $CAT $logfile > $oldlog