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.