Perl and Net::Telnet (322 Views)
Posts: 47
Registered: ‎06-10-2003
Message 1 of 2 (322 Views)
Accepted Solution

Perl and Net::Telnet

I have written the following script to access one of my cisco 3524

use Net::Telnet ();
$t = new Net::Telnet (Timeout => 1, Errmode=>'die');
@lines = $t->cmd("who");
print @lines;

The script times out at the following line:

@lines = $t->cmd("who");

I get a "command timed-out at U:\PerlScripts\ line 7"

If i comment out the above line the script executes, I believe the
waitfor line works fine, my actual prompt is SBR-3524-1>


I have staired at this for hours, any help is appreciated. What am I
doing wrong.

Acclaimed Contributor
Posts: 17,825
Registered: ‎07-16-1998
Message 2 of 2 (322 Views)

Re: Perl and Net::Telnet

Hi Jeff:

I'm going to give you the most valuable Perl lesson I know: add the -w to generate warnings and use strict:


#!/usr/bin/perl -w

use strict;

use Net::Telnet ();
my $t = new Net::Telnet (Timeout => 5, Errmode=>'die');
$t->waitfor('/Password\: /i');
my @lines = $t->cmd("help");
print "Lines: ",@lines,"\n";

Note that with -w you will see that your \s is not a recognized pattern. I changed your "who" to "help" because the "who" command is not recoginized on a Catalyst 5500 although I assume "who" is a valid command on a 3524.

If it ain't broke, I can fix that.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.