-1

i am trying to make a simple shell script Plugin to monitor Log files for specific words in a log file via nagios .But when ever i try to run the script with nagios it returns a false resulse .it alway exicutes he last line of the script and neglects all other commands .But when i try too run the script on terminal the script is working accurate. Please can any one help me regarding the script.

!/bin/bash

word1="flag"

word2="subscriber_master"

word3="success"

word4="Queryyyyselect"

word5="STDOUT"

word6="CALLSTART"

word7="HFA"

word8="SVA"

word9="SCA"

word10="SLBSA"

word11="SFA"

word12="EMVA"

word13="EMCA"

word14="EMLBSA"

word15="EMFA"

word16="DEACT"

word17="MSISDN"

word18="ADD HIT"

word19="BADDI"

word20="EmergencyRetry"

word21="USSDR"

word22="ExtendedEmergencyRetry"

word23="DELET AUDIO"

word24="IVREmergencyLogger"

word25="VAACTION"

word26="PRS"

word27="YNO"

filename="/root/Desktop/server.log"

ECHO="/bin/echo"

GREP="/bin/egrep"

TAIL="/usr/bin/tailf"

returnStateOK=0

returnStateWarning=1

returnStateCritical=2

returnStateUnknown=3

a=timeout 2 "$TAIL" "$filename"

{

for word in $word{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27}

do

if [[ $( "$ECHO" "$a"|"$GREP" -wo "$word") =~ "$word" ]]

then

"$ECHO" " OK: "$word" found "

exit=$returnSTateOK

fi

if [[ $( "$ECHO" "$a"|"$GREP" -wo "$word") != "$word" ]]

then

"$ECHO" "WARNING: "$word" not found"

exit=$returnStateCritical

fi

done

}

Community
  • 1
  • 1
  • 2
    Please re-format the code. Remove unnecessary blank lines. Use Ctrl + K or the `{}` button in the button bar to format line(s) as code blocks. – Harry Nov 24 '13 at 06:39

2 Answers2

0

From experience my guess is this is a permission issue: The nagios user (which the plugin/script is running as) does not have privileges to read the file. You can fix file and directory permissions (maybe log to a different path if possible?) or run the script using sudo.

bryn
  • 3,155
  • 1
  • 16
  • 15
0

Worth attempting: it looks like you mispelled the OK return variable in the first condition.

exit=$returnSTateOK
drewboswell
  • 150
  • 6