Status Information: (Null) in bash script


#1

Hi

I have wrote a bash script which is checking pps for a Cisco platform. The problem is that Nagios shows me (null) in “Status Field” ?! I don’t understand why. When I start the script I get the proper output which, as I understand, should be placed int the Status Field. Any ideas why is that.
The rights on the file are 777 so it is not a problem. Below is the script:

#! /bin/bash
snmpIfDescr=‘1.3.6.1.2.1.2.2.1.2’;
snmpLocifInPktsSec=‘1.3.6.1.4.1.9.2.2.1.1.7’;
snmpLocifOutPktsSec=‘1.3.6.1.4.1.9.2.2.1.1.9’;

snmpwalk $1 -v 2c -c $2 $snmpIfDescr | grep Gigabit | awk -F. ‘{print $2}’ | awk -F= ‘{print $1}’ >temp_wynik

i=0
InPPS=0
OutPPS=0
TempInPPS=0
TempOutPPS=0
WarnIn=$3
WarnOut=$4
CritIn=$5
CritOut=$6

while read; do
i=$(($i+1))
TempInPPS=snmpwalk $1 -v 2c -c $2 $snmpLocifInPktsSec.$REPLY | awk '{print $4}'
TempOutPPS=snmpwalk $1 -v 2c -c $2 $snmpLocifOutPktsSec.$REPLY | awk '{print $4}'
InPPS=$(($TempInPPS+$InPPS))
OutPPS=$(($TempOutPPS+$OutPPS))
done<temp_wynik

#echo $InPPS
#echo $OutPPS

rm temp_wynik

if ((( “$InPPS” > 0 && “$InPPS” < “$WarnIn” )) || (( “$OutPPS” > 0 && “$OutPPS” < “$WarnOut” )));
then
echo "The Input/Outpu PPS Level is OK"
stateid=0
elif ((( “$InPPS” > “$WarnIn” && “$InPPS” < “$CritIn” )) || (( “$OutPPS” > “$WarnOut” && “$OutPPS” < “$CritOut” )));
then
echo "Warning Input: $InPPS / Output: $OutPPS PPS Level "
stateid=1
elif (( “$InPPS” > “$CritIn” && “$OutPPS” > “$CritOut” ));
then
echo "Critical Input: $InPPS / Output: $OutPPS PPS Level"
stateid=2
fi
exit $stateid


#2

are you seeing the correct output from the script when you run it? i think status = (NUll) is if there’s no output…


#3

Unfortunately yes. When I run this script I get the per output and that’s why I don’t understand why it is not working.


#4

try putting the script in crontab, pipe the output to a /tmp/ file and see if it works. you might be missing full paths to the executables you use.


#5

The problem I saw when I started the script witch command:

su - nagios -c “/scrptlocalization”

The user nagios had no rights to create temp file :slight_smile:

BTW: thank for all your help