Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Net::Telnet::Cisco and IOS-XR

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

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, 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:


near the beginning of the existing regex.

use Net::Telnet::Cisco;


my $session = Net::Telnet::Cisco->new(
    -prompt => '/(?m:^(?:[\w.\/]+\:)?[\w.-]+\s?(?:\(config[^\)]*\))?\s
Replies are listed 'Best First'.
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/ bgp ipv4 unicast summary | i XXX RP/0/RP0/

      2. sh platform

      3. admin mode

      Does anyone experience same or know a fix for below

      Thanks in advance ,

      Danny Pinto

        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++; }
        This question is in the place, only few of commands are working anybody knows why?
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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://751853]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2017-08-23 06:47 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (347 votes). Check out past polls.