I am writing a Nagios plugin and I have a "command not found" when I run it. What is wrong? Why (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


answer=snmpget -v 2c -c public . | grep -Eo 

case $answer in
        echo "OK"
        exit 0
        echo "WARNING"
        exit 1
        echo "CRITICAL"
        exit 2
        echo "UNKNOWN"
        exit 3

1 Answer 1


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

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

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

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


You must log in to answer this question.

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