You need an up-to-date list of the hardware configurations and IOS levels of all of your routers.
The Bourne Shell script in Example 1-3 uses SNMP to extract useful version information from a list of routers. By default, the script will store this data in CSV format so you can easily import it into a spreadsheet for analysis. No arguments are required or expected.
Example 1-3. inventory.sh
#!/bin/sh # # inventory.sh -- a script to extract valuable information # from a list of routers. (Name, Type, IOS version) # # # Set behaviour public="ORARO" workingdir="/home/cisco" # LOG=$workingdir/RESULT.csv infile=$workingdir/RTR_LIST snmp="/usr/local/bin/snmpget -v1 -c $public" # while read device do $snmp $device sysName.0 > /dev/null if [ "$?" = "0" ] ; then rtr=Q$snmp $device .22.214.171.124.126.96.36.199.1.3.0 | cut -f2 -d" Q type2=Q$snmp $device .188.8.131.52.184.108.40.206.220.127.116.11.2.3 | cut -f2 -d$ Q ios=Q$snmp $device .18.104.22.168.22.214.171.124.126.96.36.199.2.5 | cut -f2 -d$ Q prot=Q$snmp $device .188.8.131.52.184.108.40.206.220.127.116.11.2.4 | cut -f2 -d$ Q echo "$device, $rtr, $type2, $ios, $prot" >> $LOG fi done < $infile
The inventory.sh script extracts hardware and IOS version information directly from the routers using SNMP. This ensures that the data is up to date. You can even automate this script so it runs periodically to make sure that your inventory information is always accurate. In a large network, this is much easier than keeping track of this information manually.
By default, the script captures the device name, router type, IOS version, and IOS feature set from each router. It stores this information gathered in a CSV format file called RESULT.csv.
This script requires NET-SNMP to gather the information via SNMP. You could use a different SNMP package if you prefer, but then you will need to modify the syntax appropriately. The script expects to find the executable snmpget in the directory / usr/local/bin. Again, if you keep this file in a different location, you will need to define the correct location in the variable snmp. For more information on NET-SNMP, see Chapter 17 or Appendix A.
Before running this script in your network, you will need to modify two variables. The first is the variable called public. This value must contain your read-only SNMP community string. The script assumes that you have the same community string on all of the routers in the list. The second variable that you will need to set is workingdir, which must contain the name of the directory that you wish to run the script from.
Finally, you will need to build a file called RTR_LIST that contains the names of all of your routers, with one name on each line. The script expects to find this file in the working directory.
The output of the script is a CSV file, which you can import into a spreadsheet to analyze and sort the results as required. Table 1-4 shows an example of the script's output as it might look in a spreadsheet.
|Router||Router name||Type||IOS version||IOS feature set|
|Toronto||toronto||C2500||12.2(1d)||ENTERPRISE|FIREWALL PLUS IPSEC 56|
Chapter 17; Appendix A
Router Configuration and File Management
User Access and Privilege Levels
Handling Queuing and Congestion
Tunnels and VPNs
NTP and Time
Router Interfaces and Media
Simple Network Management Protocol
First Hop Redundancy Protocols
Appendix 1. External Software Packages
Appendix 2. IP Precedence, TOS, and DSCP Classifications