Change command line output with if then else statements

Hi,

I would like to customise the output of a plugin.

At this moment i’m using this command_line with success.
$USER1$/check_snmp -H $HOSTADDRESS$ -C public -o .1.3.6.1.4.1.21796.3.3.3.1.5.$ARG1$ | cut -d " -f 2 | awk ‘{print $1 “| perf=”$1}’

But for some resone when the device i’m monitoring has some problems with the sensors the default output is SNMP OK - “-999.9 C” instead of SNMP OK - "21.2 C"
by generating the -999.9 my graphs are totaly wrong :roll:

So I would like to add a if then else to give a error output when the value is -999.9 , but this isn’t that simple?

if I try this from the command line in bash it is working perfect
echo SNMP OK - ‘“21.2 C”’ | cut -d " -f 2 | awk ’ {print $1}’ | if “$1” = “-999.9” ]; then echo “ERROR”; else awk ‘{print $1" C"" | perfdata=" $1}’; fi

but when i use it in nagios as a command_line I get this a output: null
and this is in the nagios debug log:
[1272698204.110569] [2320.2] [pid=16321] Raw Command Input: $USER1$/check_snmp -H $HOSTADDRESS$ -C public -o .1.3.6.1.4.1.21796.3.3.3.1.5.$ARG1$ | cut -d " -f 2 | awk ’ {print $1}’ | if “$1” = “-999.9” ]
[1272698204.110615] [2320.2] [pid=16321] Expanded Command Output: $USER1$/check_snmp -H $HOSTADDRESS$ -C public -o .1.3.6.1.4.1.21796.3.3.3.1.5.$ARG1$ | cut -d " -f 2 | awk ’ {print $1}’ | if “$1” = “-999.9” ]

anyone that can help with this one :?

This also doesn’t work in nagios , but perfectly from bash commandline
echo SNMP OK - ‘"-99.9 C"’ | cut -d " -f 2 | awk ‘{ if ( $1 == -999.9 ){ print “ERROR”} else print $1" | perf="$1 }’

nagios debug output
Raw Command Input: $USER1$/check_snmp -H $HOSTADDRESS$ -C public -o .1.3.6.1.4.1.21796.3.3.3.1.5.$ARG1$ | cut -d " -f 2 | awk '{ if ( $1 == -999.9 ){ print “ERROR”} else print $1" | perf="$1 }'
Expanded Command Output: $USER1$/check_snmp -H $HOSTADDRESS$ -C public -o .1.3.6.1.4.1.21796.3.3.3.1.5.$ARG1$ | cut -d " -f 2 | awk ‘{ if ( $1 == -999.9 ){ print “ERROR”} else print $1" | perf="$1 }’