Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Net::Telnet::Cisco and IOS-XR

by VinsWorldcom (Vicar)
on Mar 19, 2009 at 20:01 UTC ( #751853=snippet: print w/ replies, xml ) Need Help??

Description:

Cisco IOS-XR introduces a new prompt format that is "breaking" Net::Telnet::Cisco. Basically, the Route Processor and CPU instance is added with a colon ":" before the router hostname. I was wondering why my Telnet sessions were "failing" but the logs showed they connected and got the prompt.

I looked for an update to Net::Telnet::Cisco, but the latest version I could find was 1.10, which is what I have installed. To get around this, I used the -prompt option when calling Net::Telnet::Cisco->new() from my script.

Under the "sub new" procedure in Cisco.pm, I found the existing prompt regex (you can't miss it). I copied that code and added the new piece and passed that in when I make the Net::Telnet::Cisco->new() call via the "-prompt" option. (See Net::Telnet for more info.)

All we're doing is adding a check for the Route Processor and CPU instance and colon before the hostname - optionally, so we don't break what's currently working. This is done with the addition of:

(?:[\w.\/]+\:)?

near the beginning of the existing regex.

In your_script.pl:
use Net::Telnet::Cisco;

...

my $session = Net::Telnet::Cisco->new(
  ...
    -prompt => '/(?m:^(?:[\w.\/]+\:)?[\w.-]+\s?(?:\(config[^\)]*\))?\s
+?[\$#>]\s?(?:\(enable\))?\s*$)/'
  ...
)
Comment on Net::Telnet::Cisco and IOS-XR
Download Code
Re: Net::Telnet::Cisco and IOS-XR
by Anonymous Monk on Jun 10, 2009 at 22:39 UTC
    Thanks a lot. I have added your suggested regex to the existing one, and the resulting one is compatible with IOS as well as IOS XR. Thanks agan, Daniel.
      Hi ,

      With following prompt I am able to get cli outputs for IOS-XR commnad

       Prompt => '/(?m:^(?:[\w.\/]+\:)?[\w.-]+\s?(?:\(config[^\)]*\))?\s?[\$#>]\s?(?:\(enable\))?\s*$)/'

      But when I in following specific commnads the perl script is timing out !!

      1. When a IOS-XR command in certain scenriois which does not respond any output

      Example - RP/0/RP0/CPU0:crs2.abc#sh bgp ipv4 unicast summary | i XXX RP/0/RP0/CPU0:crs2.abc#

      2. sh platform

      3. admin mode

      Does anyone experience same or know a fix for below

      Thanks in advance ,

      Danny Pinto

        This question is in the place, only few of commands are working anybody knows why?

        hi , i am facing the same problem...i can successfully able to telnet into the router but when i give "sh run | in route" it doesn't work..please help...i can able to see telnet success and login sucess

        use Net::Cisco; open(CONFIG,">config.txt"); print CONFIG "Router ip,Status\n"; open(ROUTERIP,"routerip.txt")or die "couldn't open routerip.txt"; open(COMMAND,"command.txt")or die "couldn't open command.txt"; while(<COMMAND>) { chomp($_); $comm=$_; } $count=0; while(<ROUTERIP>) { chomp($_); $router=$_; $tl=0; $t =Net::Telnet::Cisco->new(Host=>$router,Prompt => '/(?m:^(?:[\w.\/]+ +\:)?[\w.-]+\s?(?:\(config[^\)]*\))?\s?[\$#>]\s?(?:\(enable\))?\s*$)/' +,Timeout=>7,Errmode=>'return') or $tl=1; $lg=0; my @output = (); if($tl != 1) { print "$router Telnet success\n"; $t->login('8945','kuhdie') or $lg=1 ; if($lg != 1) { print "$router Login success\n"; print "$comm"; @output=$t->cmd(string=>"sh run | in route"); print "@output\n"; $t->close; } else { $loginstat="Login Failed"; print "$router $loginstat\n"; print CONFIG "$router,$loginstat\n"; } } else { $telnetstat="Telnet Failed"; print "$router $telnetstat\n"; print CONFIG "$router,$telnetstat\n"; } close(CONFIG); $count++; }
Re: Net::Telnet::Cisco and IOS-XR
by Anonymous Monk on Jun 30, 2010 at 08:06 UTC
    This question is in the place, only few of commands are working anybody knows why?
      Even a simple command as "sh users" , "sh interface description" does not work. Best regards, Uros Milosavljevic

        I tried again with options the following prompt works for me now

        '/(?m:^\\s?(?:[\\w.\/]+\:)?(?:[\\w.-]+\@)?[\\w.-]+\\s?(?:\(config[^\)] +*\))?\\s?[\$#>]\\s?(?:\(enable\))?\\s*$)/'

        Regards - Danny

Back to Snippets Section

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://751853]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2015-07-06 01:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (68 votes), past polls