bash SNMP 输出选项 - 如何仅获取 OID 响应值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29386707/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SNMP OUTPUT OPTIONS - How do I get the OID response value only?
提问by user2179455
I have to go through and collect a few OIDs from some SNMP enabled network printers with a BASH script I have been working on.
我必须通过我一直在使用的 BASH 脚本从一些支持 SNMP 的网络打印机收集一些 OID。
My Request:
我的请求:
snmpget -v2c -c public 192.168.0.77
.1.3.6.1.2.1.1.1
.1.3.6.1.2.1.1.2
My Actual Response:
我的实际反应:
.1.3.6.1.2.1.1.1 = Counter32: 1974
.1.3.6.1.2.1.1.2 = Counter32: 633940
The Desired Response:
期望的回应:
1974
633940314
(just the oid values only)
(仅 oid 值)
I looked and tested several options using the resource from the site below:
我使用以下站点中的资源查看并测试了几个选项:
http://www.netsnmp.org/docs/man/snmpcmd.html#lbAF
http://www.netsnmp.org/docs/man/snmpcmd.html#lbAF
-Oq
removes '=' so running
-Oq
删除 '=' 所以正在运行
snmpget -v2c -c public -Oq 10.15.105.133
.1.3.6.1.2.1.1.1
.1.3.6.1.2.1.1.2
returns
回报
.1.3.6.1.2.1.1.1 Counter32: 1974
.1.3.6.1.2.1.1.2 Counter 32: 633940314
so I know I am phrasing my request properly.
所以我知道我正确地表达了我的请求。
I am taking the values and writing them to a MYSQL dB, I set the data types in my tale schema, the request is consistent so I know the definition of the OID, so I do not need all the information I am getting back, just the value of the OID itself, so I can write it to my dB without manipulating the the response. I probably can manipulate the response pulling the information to the right of ":" and writing the value of the OID.
我正在取值并将它们写入 MYSQL dB,我在我的故事模式中设置数据类型,请求是一致的,所以我知道 OID 的定义,所以我不需要我返回的所有信息,只是OID 本身的值,所以我可以将它写入我的 dB 而不操作响应。我可能可以操纵响应将信息拉到“:”的右侧并写入 OID 的值。
I am relatively new to SNMP (http://www.net-snmp.org/), but I can not see why this is not a more commonly asked question because I have been searching everywhere for an answer and this post is my last recourse...
我对 SNMP ( http://www.net-snmp.org/)比较陌生,但我不明白为什么这不是一个更常见的问题,因为我一直在到处寻找答案,这篇文章是我的最后一篇追索...
回答by steffen
You can tune the output with the -O
argument:
您可以使用-O
参数调整输出:
snmpgetnext -Oqv -v 2c -c public 192.168.0.77 .1
2
See the --help
:
见--help
:
q: quick print for easier parsing
v: print values only (not OID = value)
回答by tripleee
You can postprocess the output with a simple Awk or sed
script, or even just grep
(provided you have grep -P
).
您可以使用简单的 Awk 或sed
脚本对输出进行后处理,或者甚至只是grep
(如果您有grep -P
)。
snmpget -v2c -c public 192.168.0.77 <<'____HERE' | awk '{ print }'
.1.3.6.1.2.1.1.1
.1.3.6.1.2.1.1.2
____HERE
or
或者
.... | sed 's/.*: //'
or
或者
.... | grep -oP ':\K[0-9]+'