在Bash中解析SNMP输出 [英] Parse SNMP output in Bash
本文介绍了在Bash中解析SNMP输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要处理来自以下命令的输出文本:
I need to process the text output from the below command:
snmpwalk -v2c -c community 192.168.122.15 .1.3.6.1.4.1.14823.2.2.1.4.1.2.1.39
原始输出是:
的SNMPv2-SMI :: enterprises.14823.2.2.1.4.1.2.1.39.252.200.151.233.54.69.197.39.5.77 = STRING:Android的
我需要的输出看起来像
197.39.5.77="Android"
197.39.5.77
是最后四位数字的 =
符号前。
197.39.5.77
is the last four digits before the =
sign.
推荐答案
如果在preFIX完全是静态的,只是将其删除。
If the prefix is completely static, just remove it.
result=$(snmpwalk -v2c -c community 192.168.122.15 .1.3.6.1.4.1.14823.2.2.1.4.1.2.1.39)
result=${result#'SNMPv2-SMI::enterprises.14823.2.2.1.4.1.2.1.39.252.200.151.233.54.69.'}
echo "${result/ = STRING: /}"
或者你可以做
oldIFS=$IFS
IFS=' .'
set $($(snmpwalk -v2c -c community 192.168.122.15 .1.3.6.1.4.1.14823.2.2.1.4.1.2.1.39)
IFS=$oldIFS
shift 16
result="$1.$2.$3.$4=$7"
将数值参数移
和 $ {VAR / STR / SUBST}
构造是bash化。
这篇关于在Bash中解析SNMP输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文