X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins-scripts%2Fcheck_log.sh;h=8145bba935b60aa0d228058baaddd7af5223023e;hb=1c229b2c4572f1fcf5e1fe470f49df49111816f5;hp=0f221565e342d4e5c5d9fb17ad89c028ba5f7eb6;hpb=4907426318fc394c3d11ba71a0694a0732cf8bf0;p=nagiosplug.git diff --git a/plugins-scripts/check_log.sh b/plugins-scripts/check_log.sh index 0f22156..8145bba 100755 --- a/plugins-scripts/check_log.sh +++ b/plugins-scripts/check_log.sh @@ -1,4 +1,4 @@ -#! /bin/sh +#!/bin/sh # # Log file pattern detector plugin for Nagios # Written by Ethan Galstad (nagios@nagios.org) @@ -61,11 +61,13 @@ 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,[\\/][^\\/][^\\/]*$,,'` @@ -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,8 +193,8 @@ 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 @@ -198,7 +203,7 @@ $DIFF $logfile $oldlog > $tempdiff 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