Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Net::Telnet::Cisco - command timed-out error

by ArifS (Beadle)
on Oct 20, 2014 at 21:06 UTC ( [id://1104497]=perlquestion: print w/replies, xml ) Need Help??

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

I am using the following script, and it works fine with Host1-
HostName1#, host =172.16.1.1, port =23

OUTPUT:
Configuration register is 0x2102
Press any key to continue . . .

but it doesn't work with Host2-
HostName2#, host =10.10.1.2, port =7012

I get an error:
command timed-out at c:\temp\dir5CFE.tmp\telnet.pl line 6
3 use Net::Telnet::Cisco; 4 5 my $cs = Net::Telnet::Cisco->new( Host => '10.10.1.2', Port => +'7012', ); 6 $cs->login( 'user', 'pass' ); 7 8 # Execute a command 9 my @cmd_output = $cs->cmd( 'show ver | inc Configuration' ); 10 print @cmd_output; 11 12 $cs->close;
But both devices work fine while I use Putty to telnet in. Please let me know.

Replies are listed 'Best First'.
Re: Net::Telnet::Cisco - command timed-out error
by Loops (Curate) on Oct 21, 2014 at 03:56 UTC

    Given the line number, it's the login that's failing. This suggests that it's not seeing the login prompt that it's expecting and timing out. That's a difference between devices you might not notice with Putty. Add: Dump_Log => 'cisco.log' to your new() parameters and see what is going over the network.

      I have modified the code as following-
      use Net::Telnet::Cisco; my $cs = Net::Telnet::Cisco->new( Host => '10.10.1.1', Port => '7012', Prompt => '/(?m:^\W?[\w\/\d.:-]+[>#])/', Dump_Log => 'cisco.log', ); $username = "user"; $password = "pass"; $cs->waitfor_pause(1); $cs->print($username); print "user logged\n"; $cs->waitfor_pause(1); $cs->print($password); print "went thru\n"; # Execute a command my @cmd_output = $cs->cmd( 'show ver | inc Configuration' ); print @cmd_output; $cs->close;
      Getting error:-
      user logged went thru command timed-out at c:\temp\dirA9AB.tmp\telnet-2-port-test.pl line 23 Press any key to continue . . .
      line 23: my @cmd_output = $cs->cmd( 'show ver | inc Configuration' );
      Please let me know.
        print "user logged\n";
        actually, that is a lie, that should read
        print "username sent without checking if the Cisco wanted it at all";
        and likewise for
        print "went thru\n";

        You did set dump_log, so Net::Telnet::Cisco should have logged what the remote device sent. What does cisco.log contain?

        Update/explanation: despite its name, waitfor_pause does not wait for anything, just sets a time for ->waitfor()

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1104497]
Approved by Athanasius
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-19 23:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found