<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><DIV>Problem: Trying to read a pipe delimited file to retrieve status and port number is resulting in an "Return code of 141 is out of </DIV>
<DIV>bounds" error.</DIV>
<DIV><BR>Sample file being read, in this example, assume you want to collect servera and a status of "running" or "stopped". If the status </DIV>
<DIV>is "running", then the status should appear as ok in Nagios. If the status is "stopped", then an email should go out indicating </DIV>
<DIV>the port is down.</DIV>
<DIV>File being read has this (note: those are spaces before and after the pipes)<BR>-------------------------<BR>servera | 123 | Running   <---would show as "Port 123 is okay" in Nagios if working properly <BR>servera | 321 | Stopped   <---would show as "Port 321 is down" in Nagios if working properly<BR>servera | 456 | Running<BR>serverb | 123 | Stopped<BR>serverb | 321 | Running<BR>serverb | 456 | Running</DIV>
<DIV>Here is the script residing in libexec called app_port_monitoring.sh<BR>---------------------------------------------------------------------<BR>#!/bin/ksh<BR># </DIV>
<DIV>GREPCMD=/usr/bin/grep<BR>SSHCMD=/usr/local/bin/ssh<BR>ECHOCMD=/usr/bin/echo<BR>NAGIOSDIR=/apps/nagios</DIV>
<DIV>STATE_OK=0<BR>STATE_WARNING=1<BR>STATE_CRITICAL=2<BR>STATE_UNKNOWN=3<BR>STATE_DEPENDENT=4</DIV>
<DIV>while getopts :u:s:p:h: OPT<BR>do<BR>case $OPT in<BR>        u|+u ) export USER=$OPTARG ;;<BR>        s|+s ) export SERVERNAME=$OPTARG ;;<BR>        p|+p ) export PORT=$OPTARG ;;<BR>        : ) $ECHO "$OPTARG requires an argument"; exit $STATE_UNKNOWN;;<BR>        \? ) $ECHO "$OPTARG: bad option, use -h for help"; exit $STATE_UNKNOWN;;<BR>        h|+h ) $ECHO "Usage: `basename $0` -u USER -s SERVERNAME -p PORT" ; exit $STATE_UNKNOWN;;<BR>esac<BR>done</DIV>
<DIV><BR>if [ -z "$SERVERNAME" ]; then<BR>echo "No SERVER specified"<BR> exit $STATE_UNKNOWN<BR>fi</DIV>
<DIV>SSH_STATUS=`$SSHCMD -l ${USER} ${SERVERNAME} "pwd" >/dev/null; echo $?`<BR>        if [ $SSH_STATUS -ne 0 ]; then<BR>                echo "Cannot ssh to $SERVER"<BR>                exit $STATE_UNKNOWN<BR>        fi</DIV>
<DIV><BR>/usr/bin/ksh 'ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no -l ${USER} ${SERVERNAME} "export SHELL=bash; cd EEM; . ./ldap<BR>-bash-traversal; . ./healthcheck; export LD_LIBRARY_PATH=\"\$LD_LIBRARY_PATH:/opt/app/${USER}/servers/lib\"; export PATH=\"\$PA<BR>TH:/usr/local/bin:/bin\"; ldaphealth; . ./proxy_healthcheck"' |egrep -i 'stopped|running' | grep $USER | grep $PORT </DIV>
<DIV>>/tmp/foo_output 2>&1</DIV>
<DIV><BR># File doesn't exist or doesn't have size greater than zero<BR>if [[ -f /tmp/foo_output ]]; then<BR> echo "file exists"<BR>else<BR> echo "file not found"<BR> exit $STATE_UNKNOWN<BR>fi</DIV>
<DIV>while read LINE; do<BR>echo ${LINE}<BR> STATUS=$(echo ${LINE} | awk {'print $5'})<BR> PORT=$(echo ${LINE} | awk {'print $3'})<BR>       if [ -z "$STATUS" ]; then<BR>                echo "Service check problem"<BR>                EXITSTATUS=$STATE_UNKNOWN<BR>        elif [ "$STATUS" = Stopped ]; then<BR>        echo "${PORT} is down"<BR>               EXITSTATUS=$STATE_CRITICAL<BR>        elif [ "$STATUS" = Running ]; then<BR>&
 nbsp;       echo "${PORT} is okay"<BR>               
 EXITSTATUS=$STATE_OK<BR>       else<BR>                EXITSTATUS=$STATE_UNKNOWN<BR>       fi</DIV>
<DIV><BR>done < /tmp/foo_output</DIV>
<DIV><BR>rm -f /tmp/foo_output</DIV>
<DIV>exit $EXITSTATUS</DIV>
<DIV>---------------------------------<BR>I can place a set -x at the top of the script above and run it....below is the pertinent output</DIV>
<DIV>+ read LINE<BR>+ echo servera | 123 | Running<BR>servera | 123 | Running<BR>+ + awk {print $5}<BR>+ echo servera | 123 | Running<BR>STATUS=Running<BR>+ + awk {print $3}<BR>+ echo servera | 123 | Running<BR>PORT=123<BR>+ [ -z Running ]<BR>+ [ Running = Stopped ]        <---- problem ??<BR>+ [ Running = Running ]        <---- problem ??<BR>+ echo 123 is okay<BR>123 is okay<BR>+ EXITSTATUS=0<BR>+ read LINE<BR>+ exit 0            <--- exiting normally</DIV>
<DIV><BR>Please let me know if additional information (like the service file info) is needed.  Thanks much for any input in getting this </DIV>
<DIV>resolved.</DIV></td></tr></table><br>