Nagios script output
Hi I'm hoping someone can help me solve a problem I'm having with a script I'm running in nagios.
That's the bash script I'm calling as a service. It runs a stored procedure given an extension as a variable and returns the time in seconds since the phone last communicated with the server.
## Echo stored procedure name and extension
OUTPUT=$(echo Check_Phone_Last_Activity $1 > my.sql | cat my.sql | isql -b -w -v SWYX_Db user pass | awk 'NR==12' | sed -e 's/<.*>//g')
echo Last Activity: "$OUTPUT"
if [[ "$OUTPUT" < "120" ]]; then exit 0
The part that's causing trouble is the output, running from the command line i get the desired result e.g Last Activity: 12 however when run in nagios the status information just reads Last Activity and doesn't seem to receive the time in seconds.
The if statement is used to determine if the connection has been lost, if the time is less than 120 seconds then it exits with a return code of 0 (ok) or if its longer return code of 2 (critical) this also seems to have no affect in nagios.
I'm sure there is something staring me in the face but i dont have much experience with nagios or bash scripting. So any ideas or suggestions are welcome.
Why write the sql out to a file and then immediately cat it again? that's a good contender for the useless cat award.
Anyway, I will look at it more closely tomorrow when I have a copy of nagios at my fingertips.
Edit: in fact, isql gets the useless cat award all on its own. I'm astounded that it can't take its own input (filing a bug ;))