C.2. Common Command-Line Arguments
For the most part, the Net-SNMP
commands follow a similar command structure; they share many options
and use roughly the same syntax. For example, in the abstract, an
snmpget command looks like this:
snmpget options hostname community objectID...
In other words, the command name is followed by a series of options,
the hostname of the system you want to poll, the community string,
and one or more object IDs. (Note that you can use the
-c community option instead of placing the
community string after the hostname. You can also provide a default
hostname in your snmp.conf file.) The syntax of
snmpset is only slightly different; because
snmpset changes object values, it requires you to
specify the object's datatype and the new value:
snmpset options hostname community objectID type value...
Table C-1
summarizes some of the most useful options that are common to all
Net-SNMP commands. See the snmpcmd(1) manpage for a complete list.
Table C-1. Summary of Command-Line Options
Option
|
Description
|
-m
|
Specifies
which MIB modules you would like the command to load. If you want the
command to parse the MIB file for a particular vendor, copy the MIB
file to /usr/local/share/snmp/mibs and invoke
the command with the option -m ALL. The argument
ALL forces the command to read all the MIB files
in the directory. Setting the environment variable $MIBS to
ALL achieves the same thing. If you don't
want the command to read all the MIB files, you can follow the
-m option with a colon-separated list of the MIB
files you want parsed.
|
-M
|
Allows you to specify a colon-separated list of directories to search
for MIB files. This option is useful if you don't want to copy
MIB files into the default MIB location. Setting the shell variable
$MIBDIRS has the same effect.
|
-IR
|
Performs a random-access search through
the MIB database for an OID label. By default, the commands assume
that you specify an object ID relative to
.iso.org.dod.internet.mgmt.mib-2. In practice,
this option allows you to avoid typing long OIDs for objects that
aren't under the mib-2 subtree. For
example, there's a group of objects in the Cisco MIB named
lcpu. If you use the -IR
option, you can retrieve objects in this group without typing the
entire OID; the following command is sufficient:
snmpget -IR hostname community lcpu.2
If there is more than one object with the given name, the Net-SNMP
tools will access the first object they find. Since this feature is
billed as a random-access search, there's no way to predict
which object the tools will find first. Within the standard MIBs,
objects rarely (if ever) have the same name, but there's no
guarantee that any name will be unique, particularly if you're
using vendor-specific MIBs.
|
-On
|
Prints OIDs numerically (e.g.,
.1.3.6.1.2.1.1.3.0). Note that the
-O options can be combined, as long as the
combination makes sense.
|
-Of
|
Prints the entire OID (i.e., starting with .1).
|
-Os
|
Displays only the final part of the OID, in symbolic form (e.g.,
sysUpTime.0).
|
-OS
|
Same as -Os, but prefixes the object name with the
name of the MIB file from which the object is taken (e.g.,
SNMPv2-MIB::sysUpTime.0).
|
-T
|
Specifies whether the command should use TCP or UDP as the
transport-layer protocol. UDP is the default; -T
tcp uses TCP.
|
-v
|
Specifies which version of SNMP to use. By default, the commands use
Version 1. Valid options are -v 1, -v
2c, and -v 3. Note that some
commands, such as snmpbulkget, are available only
for Versions 2c and 3.
|
-h
|
Displays help information for the command.
|
-c
|
Specifies the community string for the command. Alternately, you can
place the community string after the hostname and omit the
-c option.
|
| | | C. Net-SNMP Tools | | C.3. Net-SNMP Command-Line Tools |
Copyright © 2002 O'Reilly & Associates. All rights reserved.
|
|