How can I change the output of a command accordding to the output of that command?
I do an snmp validation, but there are possible answers:
- The command was executed but there was no answer.
- The command was executed OK but the result was not the one I expecte (in this case, this would be the output: SNMPv2-MIB::sysUpTime.513 = No Such Instance currently exists at this OID)
- he command was executed OK and the result was the one Expected ( a different answer than No Such Instance currently exists at this OID)
I'd like that people running this script, in case option 1 or 2 are received read: " SNMP not available "
And for the 3rd option: " SNMP Available "
In my script, in option 2 my output goes to OK instead of going to Not OK
#!/bin/bash
hostname=$1
read -p "Introduce IP Address: " hostname
community="snmpcommunity"
echo "snmp validation:"
sysUpTime=`snmpget -v2c -c $comunidad $hostname 1.3.6.1.2.1.1.3.513`
if [ $? -eq 0 ]; then
echo "snmp1 ok"
else
echo "snmp1 not ok"
fi