BASH script works differently under nagios
Posted: Wed Nov 05, 2014 3:45 pm
Folks:
I have a very simple bash script to check the fan state of my Cisco switch. I can run the script from the command prompt with './' and it returns the correct values; however, when I build my command string and enable the check it blows past if condition 1 and if condition 2, and odd part about it... Nagios has my check as showing "warning", and the text as CHECK FAILED, which is the unknown status.
This is driving me crazy since I can get the correct error code from manually running the script. It appears to be something goofy about my IF statement; however, it runs correctly manually.
Thank you
/JJ/
I have a very simple bash script to check the fan state of my Cisco switch. I can run the script from the command prompt with './' and it returns the correct values; however, when I build my command string and enable the check it blows past if condition 1 and if condition 2, and odd part about it... Nagios has my check as showing "warning", and the text as CHECK FAILED, which is the unknown status.
Code: Select all
#!/bin/bash
yes=0
warn=1
err=2
un=3
test=$(snmpget -v2c -c trustedzone 192.168.14.34 CISCO-ENVMON-MIB::ciscoEnvMonFanState.5007 | awk '{print $4}')
if [ "$test" = "normal(1)" ]; then
echo "OK - 1"
return "$yes"
elif
[ "$test" = "critical(3)" ]; then
echo "CRITICAL - 2"
return "$err"
else
echo "CHECK FAILED"
return "$un"
fiThank you
/JJ/