net-snmp
命令有许多选项可以修改它们的行为和输出。我建议您阅读 、 和 的snmpcmd
手册 snmpwalk
页snmp.conf
。
检查-O
选项组snmpwalk
(见下文)。
-Oqv
组合产生一个只有数字的列:
$ clsgrpids=$(
/usr/bin/snmpwalk -Oqv -v 1 -c $COMM $HOST $OID.11.1.1.1
)
$ echo "$clsgrpids"
1
2
3
去掉引号让 shell 打印一行:
$ echo $clsgrpids
1 2 3
以下是-O
选项组中控制输出的其余选项snmpwalk
:
-O OUTOPTS
Toggle various defaults controlling output display:
0: print leading 0 for single-digit hex characters
a: print all strings in ascii format
b: do not break OID indexes down
e: print enums numerically
E: escape quotes in string indices
f: print full OIDs on output
n: print OIDs numerically
q: quick print for easier parsing
Q: quick print with equal-signs
s: print only last symbolic element of OID
S: print MIB module-id plus last element
t: print timeticks unparsed as numeric integers
T: print human-readable text along with hex strings
u: print OIDs using UCD-style prefix suppression
U: don't print units
v: print values only (not OID = value)
验证(实际运行代码)
$ snmpwalk -Ov -v1 -c public localhost sysUptime
Timeticks: (66595) 0:11:05.95
$ snmpwalk -Oqv -v1 -c public localhost sysUptime
0:0:11:35.13
$ snmpwalk -Otqv -v1 -c public localhost sysUptime
70012