1

I am writing a Nagios plugin and I have a "command not found" when I run it. What is wrong? Why 127.0.0.1 (or localhost as well) is not recognized? When I run just the snmp request - I have a simple number as an output - so everything works perfectly.

Here is the script

#!/bin/bash

answer=snmpget 127.0.0.1 -v 2c -c public .1.3.6.1.4.1.2021.11.9.0 | grep -Eo 
'[0-9]+$'

case $answer in
    [1-2]*)
        echo "OK"
        exit 0
        ;;
    [3-50]*)
        echo "WARNING"
        exit 1
        ;;
    [51-100]*)
        echo "CRITICAL"
        exit 2
        ;;
    *)
        echo "UNKNOWN"
        exit 3
        ;;
esac

1 Answer 1

4

Your variable assignment is not correct. You are looking for command substitution:

answer=$(snmpget 127.0.0.1 -v 2c -c public .1.3.6.1.4.1.2021.11.9.0 | grep -Eo '[0-9]+$')

As you have written it you are setting answer=snmpget as an environmental variable for the command: 127.0.0.1 with options: -v 2c -c public .1.3.6.1.4.1.2021.11.9.0

Also note [3-50] and [51-100] almost certainly will not do what you intend. See: Can I use comparison operators in case?

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .