Cisco Blogs

Automate Getting the UCS SNMP MIBs

- March 9, 2012 - 0 Comments

I like the command line, I’ll admit it, it’s old-school but l am old-school. Clicking around a graphical interface is all well and good but if you want to get something done the command line is the way to do it. My high school years, college years and early career were a variety of Unix flavors, VMS, DOS, CP/M with an assortment of editors, programming languages and shells.

What I love is when a graphical interface can be managed via a command line.  This way I know that I can use all my favorite tools (old and new) to get done what needs to be done. What needs to get done sometimes is taking the point and click out of a task. That’s my focus today.

Here’s the scenario, download SNMP MIBs for UCS. Go to that web page and you need to get very clicky, perhaps even right-clicky and select the “save as” option. More clicks, with potentially over 100 MIBs to download that’s 200 plus clicks, and the repetition is as mind numbing as a top 40 radio station.

The command line comes to the rescue and saves your index finger and your mind. These are the *nix utilities that I use, cURL , awk, and grep. I’m sure there are other utilities that work. Leave me a comment with your solution I’d love to see it. I’m also running these utilities in Cygwin, in a Windows 7 VM, running on my MAC.  Sounds like subterfuge, you may just be on a *nix box directly, whatever works is good. The command below will retrieve the web page, extract the ftp links for each UCS version and separate by UCS version number.

curl -s |
grep -i -E '.my\"|Release [1-9]\.[0-9]</span></a>' |
awk '{if (index($0,"ftp")) {print substr($0,index($0,"ftp://"),index($0,".my\"")-index($0, "ftp://")+3)} else {print substr($0,index($0,"Release"),index($0,"</span></a>")-index($0,"Release"))}}' > mib-link-curl.txt

Once I have a list of ftp links separated by version number I can use that as input to a script that will download and package the MIBs by UCS version number. I can then give that package to a customer, a co-worker, or just post it somewhere.

I used curl to get the webpage, pretty easy it’s just curl and then the webpage, the -s tells curl to be silent about what it is doing.

curl -s

I then use grep to extract the lines of the webpage source that I am interested in. If I examine the page source for the UCS MIB listing I see a whole bunch of links for the Cisco FTP site, I can also see that the MIBs are divided into a few sections. 1.0 MIBs are for all versions of UCS Manager, and then there are 1.3, 1.4 and 2.0.  Turns out that 1.4 and 2.0 MIBs are exactly the same, 2.0 just has a couple more MIBs to support the added 2.0 functionality. I needed to identify something in the page source that indicated the beginning of each section and found these strings to work nicely.

Release 1.0</span></a>
Release 1.3</span></a>
Release 1.4</span></a>
Release 2.0</span></a>

Make that into a regular expression and it looks like this

Release [1-9]\.[0-9]</span></a>

I also needed to identify the ftp links that would be used to retrieve the MIBs, those were just as easy;


Every MIB file ftp link ended with .my”. Based on this my final regular expression and command to extract what I needed with grep looks like this;

grep -i -E '.my\"|Release [1-9]\.[0-9]</span></a>'

grep without case sensitivity  in enhanced mode, lines that have .my” in them or ones that match the Release 1.0, 1.3, 1.4 or 2.0 pattern. The regular expression will actually match “Release 1.0” through “Release 9.9”

I’ve got the webpage, extracted the lines I want and now awk will do the slicing and dicing to pull out the most interesting parts. The awk command is in one line but I’ll throw in some formatting here to make it easier to read.

awk '{
if (index($0,"ftp")) {
print substr($0,index($0,"ftp://"),index($0,".my\"")-index($0, "ftp://")+3)
} else {
print substr($0,index($0,"Release"),index($0,"</span></a>")-index($0,"Release"))

There will be two types of lines coming to awk either a line that has an ftp link to a MIB file or a line that has the “Release #.#” string in it. A simple if statement that decides what to do, if the string “ftp” is found in the line then it is an ftp line, otherwise it has to be a Release line.

If the line is an ftp line the substring and index functions of awk will extract the link and print it out. If the line is a Release line the substring and index functions will extract the Release line and print it out. All the printed output is captured in the file mib-link.txt

Here is a condensed output that you’ll end up with

Release 1.0
. Several MIB ftp links not shown
Release 1.3
Release 1.4
. Several MIB ftp links not shown
Release 2.0
. Several MIB ftp links not shown

Take this output and write a script that will read in the output download the MIBs, create directories for each version and perhaps even tar and gzip the MIBs.  Like what I have below

# John McDonough Cisco Systems, Inc.
# This script is a proof of concept of what can be done
# using standard *nix tools to download MIBs from the
# Cisco ftp site

FTPMIBLIST=${1} # Arg 1 to the script a file with a list of MIB links
DEBUG=${2}      # Arg 2 put anything as arg 2 to see debug output

while read CURLINE; do
LINETYPE=`echo ${CURLINE} | awk '{if (index($0,"ftp")) {print "ftp"} else {print "release"}}'`

if [ ${DEBUG} ]; then
echo "The Current line: ${CURLINE}"
echo "The Line type: ${LINETYPE}"

if [ ${LINETYPE} = release ]; then
RELEASEVERSION=`echo ${CURLINE} | awk '{print $2}'`

if [ ${OLDRELEASEVERSION} != "0.0" ]; then

if [ ${DEBUG} ]; then
echo "The Release version: ${RELEASEVERSION}"


MIBFILENAME=`echo ${CURLINE} | awk -F/ '{print $NF}'`

if [ ${DEBUG} ]; then
echo "The MIB filename: ${MIBFILENAME}"

curl -s --retry 2 --retry-delay 5 --create-dirs -o ${RELEASEVERSION}/${MIBFILENAME} ${CURLINE}


done < ${FTPMIBLIST}

How could you extend this script?

    Create timestamps

  • Verify all files expected to be downloaded are downloaded
  • ftp MIB files to location where NMS systems load them from
  • Schedule the running of the script for an appropriate interval
  • Adapt the script to get MIB files for other products

I hope this helps in your UCS system administration or for any other Cisco product.


In an effort to keep conversations fresh, Cisco Blogs closes comments after 60 days. Please visit the Cisco Blogs hub page for the latest content.