No output when running script from Test Command option
Posted: Fri Apr 08, 2016 1:36 pm
Hi,
Im having a problem when running a snmp script from the test command option. It shows no output as below:
Testing check from command line...
COMMAND: $USER$/check_load_avg.sh 192.xxx.xxx.xxx
OUTPUT:
However when I run the command from the CLI I get the expected results:
# su nagios
#./check_load_avg.sh 192.xxx.xxx.xxx
OK- Load Average: 1min=0.23, 5min=0.17, 15min=0.19 | '1min Load Avg'=0.23, '5min Load Avg'=0.17, '15min Load Avg'=0.19
The contents of the script is below:
#!/bin/bash
hostaddress="$1"
check_load_avg=($(snmpwalk -v2c -c community $hostaddress .1.3.6.1.4.1.2021.10 | grep -i laLoad.[1-3] | cut -d"=" -f 2 | cut -d" " -f3 | sed 'N;s/\n/ /' | sed 'N;s/\n/ /' | awk '{print $1" " $2 " " $3}'))
one_min_avg=${check_load_avg[0]}
five_min_avg=${check_load_avg[1]}
fifteen_min_avg=${check_load_avg[2]}
if [[ -z "$1" ]]
then echo "Incorrect syntax, please use check_load_average <ipaddress>"
exit 3
elif [[ -z "$check_load_avg" ]];
then "echo test"
exit 3
else
echo "OK- Load Average: 1min=$one_min_avg, 5min=$five_min_avg, 15min=$fifteen_min_avg | '1min Load Avg'=$one_min_avg, '5min Load Avg'=$five_min_avg, '15min Load Avg'=$fifteen_min_avg"
exit 0
fi
Thanks for the help in advance.
Fearghal
Im having a problem when running a snmp script from the test command option. It shows no output as below:
Testing check from command line...
COMMAND: $USER$/check_load_avg.sh 192.xxx.xxx.xxx
OUTPUT:
However when I run the command from the CLI I get the expected results:
# su nagios
#./check_load_avg.sh 192.xxx.xxx.xxx
OK- Load Average: 1min=0.23, 5min=0.17, 15min=0.19 | '1min Load Avg'=0.23, '5min Load Avg'=0.17, '15min Load Avg'=0.19
The contents of the script is below:
#!/bin/bash
hostaddress="$1"
check_load_avg=($(snmpwalk -v2c -c community $hostaddress .1.3.6.1.4.1.2021.10 | grep -i laLoad.[1-3] | cut -d"=" -f 2 | cut -d" " -f3 | sed 'N;s/\n/ /' | sed 'N;s/\n/ /' | awk '{print $1" " $2 " " $3}'))
one_min_avg=${check_load_avg[0]}
five_min_avg=${check_load_avg[1]}
fifteen_min_avg=${check_load_avg[2]}
if [[ -z "$1" ]]
then echo "Incorrect syntax, please use check_load_average <ipaddress>"
exit 3
elif [[ -z "$check_load_avg" ]];
then "echo test"
exit 3
else
echo "OK- Load Average: 1min=$one_min_avg, 5min=$five_min_avg, 15min=$fifteen_min_avg | '1min Load Avg'=$one_min_avg, '5min Load Avg'=$five_min_avg, '15min Load Avg'=$fifteen_min_avg"
exit 0
fi
Thanks for the help in advance.
Fearghal