Date created: Monday, October 5, 2015 9:28:16 AM. Last modified: Tuesday, April 2, 2019 9:50:02 PM

Feed from BASH, snmpget v2c & v3

This example script uses snmpget to poll a specific SNMP OID using either SNMP v2c or SNMP v3 (if the NMS can not support specifying SNMP OIDs):

#!/bin/bash

# SNMP v2c
#subcount=`snmpget -v 2c -c S3cr3tStr1ng 10.0.0.1 1.3.6.1.4.1.9.10.24.1.1.4.1.3.2 | awk {'print $NF'}`

# SNMP v3
##subcount=`snmpget -v 3 -n "" -u snmpuser -a MD5 -A "password" -x AES -X "authphrase" -l authPriv 10.0.0.1 1.3.6.1.4.1.9.10.24.1.1.4.1.3.2 | awk {'print $NF'}`

# Specific source IP
# subcount=`snmpwalk --clientaddr=192.168.0.123 ...`
echo -n "$subcount"