All of the net-snmp commands pick a common set of options, which the next few sections will be discussing. The only commands that do not accept these common set of arguments are the running demons (like snmpd and snmptrapd).
A list of all of the options that are available for use from a command can be printed by passing "-h" on the command lien to any of the commands.
All of the commands allow you to format their output in a manner which you personally will find attractive. The behavior is controlled using the -O flag:
Here are brief examples of all the above options in use:
This flag controls whether or not you want to display the results using numerical order to textual OIDs:
Similarly, this flag controls whether you want to display enumerated lists numerically or with textual translations:
Many SNMP tables are indexed by strings. The strings are then translated into OID segments so that they can be referenced in a SNMP request. The best way to understand this is through an example. So, let's take a look at the usmUserEntry object and how it is indexed:
As you can see by the above description, it is indexed by two different objects: usmUserEngineID, and usmUserName. Both of these are strings. The default for all of the commands is to breakdown the result for you to make it easier for you to decode the above indexes out of the printed result:
As you can see, they OID in the output above shows 2 strings in it: "........." and "MD5User". The first string is an engine ID which is full of unprintable characters, so in this case it didn't help much that the library printed it out for us. However, the user string "MD5User" got nicely printed instead. We generally think this is much easier to understand than looking at the numbers directly. However, this is available to you as an option as well:
Here you can see that the OID is much more complex, and does not intuitively look like it contains 2 strings to the naked eye.
Of course, all of the net-snmp commands also accept strings in the requested OID, although most shells will require you to escape the quotes with a back slash:
A more elaborate output for index values is -OX. This format is output-only - no provision has been made to accept it on input.
Especially the IPv6 mibs return values that can be very difficult to read, and is very different from the ways you normally see the values involved.
Consider for instance the IPV6-MIB:ipv6RouteTable
Shorting the output of those really long OIDs is also possible, using the -Os and -OS command (the -OS version pre-pends the url with the MIB name that the node came from):
% snmpget -v 2c -c demopublic test.net-snmp.org sysUpTime.0 ucdDemoUserList.0 system.sysUpTime.0 = Timeticks: (586910990) 67 days, 22:18:29.90 enterprises.ucdavis.ucdDemoMIB.ucdDemoMIBObjects.ucdDemoPublic.ucdDemoUserList.0 = " noAuthUser MD5User MD5DESUser SHAUser SHADESUser" % snmpget -Os -v 2c -c demopublic test.net-snmp.org sysUpTime.0 ucdDemoUserList.0 sysUpTime.0 = Timeticks: (586910990) 67 days, 22:18:29.90 ucdDemoUserList.0 = " noAuthUser MD5User MD5DESUser SHAUser SHADESUser" % snmpget -OS -v 2c -c demopublic test.net-snmp.org sysUpTime.0 ucdDemoUserList.0 RFC1213-MIB::sysUpTime.0 = Timeticks: (586911833) 67 days, 22:18:38.33 UCD-DEMO-MIB::ucdDemoUserList.0 = " noAuthUser MD5User MD5DESUser SHAUser SHADESUser"
As you can see the above options only print out the last node in the OID, but the -OS option additionally prepends the output with the name of the MIB that the OID can be found in.
-Of Is sort of the reverse of the previous options and always displays the full OID:
The -Ov flag outputs only the value, but not variable name
Finally, the -Oq flag allows us to print everything as quick as possible in a fashion that is easily parsible by things like scripting languages:
Note that in the above output, there is no equal sign and there is no "OID:" string in the output.
Of course, you're allowed to combine many of these options into one statement:
For shell scripts, the -Oqv option is useful. It only returns the value of the attribute, which is useful for instance in (using sh/ksh/bash syntax)
Last modified: Thursday, 26-May-2011 23:21:32 UTC
For questions regarding web content and site functionality, please write to the net-snmp-users mail list.