Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Cisco weirdness under Net::Telnet when "enabled"

by fx (Pilgrim)
on Jun 01, 2011 at 13:31 UTC ( [id://907628] : perlquestion . print w/replies, xml ) Need Help??

fx has asked for the wisdom of the Perl Monks concerning the following question:

I would like to start by saying that I cannot use Net::Telnet::Cisco due to constraints on installing software on the machine in question.

I have a weird issue when talking to my Cisco devices using Net::Telnet - but only when I am running "enabled" within the router. Code:

#!/usr/bin/perl -w use strict; use Net::Telnet; my $t = new Net::Telnet( Input_log => 'log.txt', Prompt => '/cis-.+[>#]/' ); ## Note - all my Cisco devices have hostnames beginning with "cis-" ## so hence the custom prompt setting here. $t->open('10.10.10.1'); $t->login('username1', 'password1'); $t->cmd('term length 0'); print $t->cmd('where'); ## Everything above this line works as I expect ## Things below this line seem to go a bit weird... $t->print('enable'); $t->waitfor('/Password:/'); $t->print('password1'); $t->cmd('term length 0'); print $t->cmd('where'); $t->close();

Now, any command issued before the "enable", as the regular user, works and output is as expected. I've used "where" here as it's pretty universal but under some devices you can also "sh version" as a normal user. Basically, the result of running that line is the printing of the output as expected.

I have also proved that the elevation from regular user to enabled super-user works.

The problem seems to occur in the code AFTER I do the "enable". For example, the code as displayed does NOT print the output of the "where" command after enabling. Replace this with anything else that produces output (such as "sh ver" or "sh run" or something) and still nothing. HOWEVER... if a second "print $t->cmd..." command is added after the enabling, then the output of the FIRST enabled command gets printed after the SECOND enabled command has run.

As you can see, I also capture the input from the device into a file (log.txt in this case) and the contents of that file agrees with what I see on the screen.

Can someone please suggest where I could be going wrong here?.....

fx, Infinity is Colourless

Replies are listed 'Best First'.
Re: Cisco weirdness under Net::Telnet when "enabled"
by VinsWorldcom (Prior) on Jun 01, 2011 at 14:22 UTC

    Shot in the dark, but try 'binmode':

    my $t = new Net::Telnet( Input_log => 'log.txt', binmode => 1, Prompt => '/cis-.+[>#]/' );

    This worked when I used N::T::C to connect to Quagga routers that exhibited that behavior (reply from first command after second is issued).