I have one simple bash script calls test_snmp, let's say:
#!/bin/bash
echo $1
I have snmpd.conf set as following:
rwcommunity public 127.0.0.1
extend .1.3.6.1.4.1.2021.53 /bin/bash /tmp/test_snmp
What I'd like to do is to run a snmpwalk command, something like:
snmpwalk -v2c -c public 127.0.0.1 .1.3.6.1.4.1.2021.53 "PRINT SOMETHING"
from the output I see that
oid = iso.3.6.1.4.1.2021.53.3.1.1.9.47.98.105.110.47.98.97.115.104 = ""
, is the output of the script. But I'd like to pass that string "PRINT SOMETHING"
, as a $1
parameter for the script mentioned above and then get the string (in this case "PRINT SOMETHING"
) by using snmpget
command, something like:
snmpget -v2c -c public 127.0.0.1 iso.3.6.1.4.1.2021.53.3.1.1.9.47.98.105.110.47.98.97.115.104
It is only an example, I'm testing what options I have by running scripts via snmp, because if this works then I'll write another scripts to run remotely, but I have to run them with variables.
Does anyone know how to do it?
Thank you
I spent lot of time before found all answers. I hope, it will be start point for someone and will save time.
/etc/snmp/snmpd.conf:
rwcommunity public
pass .1.3.6.1.4.1.YOUR_NUM_HERE.1 /path/to/your/script.sh
/path/to/your/script.sh:
#!/bin/bash
case "$1" in
-g) // GET Req
echo $2 # ANSWER OID
echo "string" # string/int/etc...
echo "you data" #
;;
-s) // SET Req
# Your code for processing SET Req
exit 0
;;
-n) // GETNEXT Req
echo $2
echo "string"
# Your code for processing GETNEXT Req
;;
*)
;;
esac
You can use snmpwalk after that and place your code after "-n" case. In case of snmpget, you code will be after "-g"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With