By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,807 Members | 1,492 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,807 IT Pros & Developers. It's quick & easy.

Perl script to look only for the desired keyword on cisco router

P: 2
Hi Guys,

I'm new to Perl and to this forum and I hope you gurus here help me.

I am building a perl script that will telnet to one of my cisco router and execute commands. I was able to do this task using perl module Net::Telnet::Cisco and able to execute router commands successfully.

I want is for example. from cisco "show version" commands, I only want to appear only the

myrouter uptime is 16 weeks, 3 days, 23 hours, 50 minutes
System returned to ROM by bus error at PC 0x60279CDC, address 0x0 at 16:52:00 Fri Jul 20 2007
System restarted at 16:52:14 Fri Jul 20 2007
System image file is "flash:c5350-js-mz.123-1.bin

I only want to appear only that line and omit other lines that are irrevelant.

b. another example is like I only want to know the CRC errors, or if the interface is UP or down when i execute the "show interfaces" command.

To sum up, I only want to display by executing the commands the lines or keywords that I want

Hope you can help me on this.thanks in advance
Sep 5 '07 #1
Share this Question
Share on Google+
3 Replies


KevinADC
Expert 2.5K+
P: 4,059
I am totally unfamiliar with cisco router commands. Do the commands display more lines that you want? Is that normal? What does get displayed?
Sep 5 '07 #2

P: 2
I'll cite an example, my perl script will execute this router commands

myrouter#show health-monitor
Chassis:
Power Supply OK
Redundant Power System is present.
PS Input Voltage status: normal
PS Output Voltage status: normal
PS Fan status: normal
PS Thermal status: normal
PS OverVoltage status: normal
Temperature OK
Fans OK

Memory:
Free Memory processor OK
Memory Fragmentation Processor OK
Free Memory I/O OK
Memory Fragmentation I/O OK
Memory summary:

it will display several lines,let say I only want to display this 3 lines just to summarize

Power Supply OK
Temperature OK
Fans OK

and omit the other lines that are not so relevant


do i use cut, awk grep command?
Sep 6 '07 #3

KevinADC
Expert 2.5K+
P: 4,059
Net::Telnet::Cisco is a subclass of Net::Telnet which allows you to define search patterns. I am pretty sure its the "waitfor" option. See Net::Telnet for details about defning search patterns:

cpan: Net::Telnet
Sep 6 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.