"No Output" issue

I have the following script that I created to check the number of connections using the ldapsearch command. The script works fine from the command line, however, the “Status Information” column of the Nagios website shows “No Output”.

GREPCMD=/usr/bin/grep

STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4

while getopts :s:u:h: OPT
do
case $OPT in
s|+s ) export SERVERNAME=$OPTARG ;;
u|+u ) export USER=$OPTARG ;;
: ) $ECHO “$OPTARG requires an argument”; exit $STATE_UNKNOWN;;
? ) $ECHO “$OPTARG: bad option, use -h for help”; exit $STATE_UNKNOWN;;
h|+h ) $ECHO "Usage: basename $0 -u USER -s SERVERNAME " ; exit $STATE_UNKNOWN;; esac done

if -z “$SERVERNAME” ]; then
echo "No SERVER specified"
exit $STATE_UNKNOWN
fi

ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no -l ${USER} ${SERVERNAME} “export SHELL=bash; cd EEM; . ./ldap-bash-traversal; . ./healthcheck; export LD_LIBRARY_PATH=”$LD_LIBRARY_PATH:/opt/app/${SERVERNAME}/servers/lib"; ldaphealth" >foo

grep ${SERVERNAME} foo | awk {‘print $5’} > newfoo
for LINE in $(cat newfoo); do
echo ${LINE}
if -z “$LINE” ]; then
echo "There appears to be a problem with this service check."
EXITSTATUS=$STATE_UNKNOWN
elif $LINE -eq 0 ]; then
echo "No connections found"
EXITSTATUS=$STATE_CRITICAL
elif $LINE -gt 0 ]; then
echo "${LINE} connections exist"
EXITSTATUS=$STATE_OK
else
EXITSTATUS=$STATE_UNKNOWN
fi
echo ${EXITSTATUS}
done

rm -f foo
rm -f newfoo

exit $EXITSTATUS

Any suggestions would greatly be appreciated.

Hi!
Well, the answer is quite easy, and always the same:
nrpe/nagios doesn’t work with the same environnement variables as you do when running in command line, especially the “current working dir”.

Meaning:
when you write to “foo” (at the end of your ssh), ask yourself where this file will be located (the current working dir of nagios is /, if i’m correct). So specify the full path of “foo” (and do the same when you grep it).
the same applies to “newfoo”, of course :wink:

Also, you correctly define the grep command if “GREPCMD=/usr/bin/grep” => use it :slight_smile:
do the same for ssh => define the full path (/us/bin/ssh) and use it

well, I think you got the idea now, so if there are other mistakes, you will easily find them.

Also, when you have this kind of errors, it always pay to remove the “rm -f foo” and “rm -f newfoo” and have a look at the content of theses files when executed by nagios; you may have some surprises (usually bad surprises, of course :)).

hope this solves your problem and future problems as well :slight_smile:

Thanks Loose, your suggestions worked. I setup the foo and newfoo as /tmp/foo and /tmp/newfoo and I also added SSHCMD=/usr/local/bin/ssh and I now have output. Thanks again !!