Bash exit codes
Posted: Wed Apr 30, 2014 7:07 am
Hello,
I'm trying to get some logging done in a bash script that will update my nsclient.ini, but I'm having issues with the exitcode given by the check_nrpe.
This is the code:
The log file shows however:
Although I'm 100 % sure the nsclient.ini file was updated and the $EXITCODE is 0, so somehow the if statement is nto working as expected. Any tips?
Willem
I'm trying to get some logging done in a bash script that will update my nsclient.ini, but I'm having issues with the exitcode given by the check_nrpe.
This is the code:
Code: Select all
#!/bin/bash
HOSTNAME=$1
LOGFILE=/var/log/update_nscp_ini_legacy.log
NOW=$(date '+%Y-%m-%d -- %H:%M')
echo "$NOW : Nsclient legacy ini update started on $HOSTNAME." >> /var/log/update_nscp_ini_legacy.log
/usr/local/nagios/libexec/check_nrpe -H wingatewayserver -t 300 -c update_nscp_ini_legacy -a $HOSTNAME
EXITCODE=$?
echo "$NOW : Exit code $?" >> /var/log/update_nscp_ini_legacy.log
NOW=$(date '+%Y-%m-%d -- %H:%M')
if [$EXITCODE -eq 0]
then
echo "$NOW : Nsclient legacy ini update succeeded on $HOSTNAME, with exit code $EXITCODE" >> /var/log/update_nscp_ini_legacy$
else
echo "$NOW : NSClient legacy ini update failed on $HOSTNAME, with exit code $EXITCODE" >> /var/log/update_nscp_ini_legacy.log
fi
exit 0
Code: Select all
2014-04-30 -- 14:01 : Nsclient legacy ini update started on servername.
2014-04-30 -- 14:01 : Exit code 0
2014-04-30 -- 14:01 : NSClient legacy ini update failed on servername, with exit code 0
Willem