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
}