Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to write a perl script which logs into cisco switches via telnet and parses the output of show mac-address-table. The problem is that different switches show me a different field layout.

The WS-C3548-XL shows the fields in the order

Destination Address Address Type VLAN Destination Port

while the C2960 shows it like

Vlan Mac Address Type Ports

is there a way to tell show to print the fields in a predefined order?

share|improve this question
You can handle this in your script by checking the output header. – Khaled Nov 24 '11 at 13:41
Have a look at how NeDi does this. – al. Nov 24 '11 at 13:52
telnet [shivers], I don't understand why this prehistoric, clear text protocol is still supported on these devices. Can't you use ssh instead? – Alex Nov 24 '11 at 15:11
Parsing the output is doing it wrong. Use SNMP. – Tom O'Connor Nov 24 '11 at 17:38
up vote 5 down vote accepted

Poll the devices using SNMP. I would think the MIBs are the same but you never know with Cisco.

share|improve this answer
yes, i solved it now via snmp. i only tried the telnet approach because i couldn't find the right oids, but it finally seems to work with RFC1286-MIB – tintifaxx Nov 25 '11 at 18:11

No, not that I know of.

But since you're already using perl, just check the first line. From there on, you know what the meanings of the particular fields are, and fill your hash (I hope you're using one!) accordingly. This has the additional advantage that in the future, you can support other models with yet another output format. While still supporting the "old" ones. Robust programming.

...Oh, and make sure to handle the space in "Address Type" :)

share|improve this answer

Have you thought of scripting using SNMP You can run external snmpget / snmpwalk utilities and parse the output or use the Net::SNMP module.

share|improve this answer

SNMP would be best. But also remember that the "include" output modifier is regex capable. You could just grab the info you want if you want stick with Perl-expect

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.