Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
cancel
Showing results for 
Search instead for 
Did you mean: 

Perl and Net::Telnet

SOLVED
Go to solution

Perl and Net::Telnet

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

use Net::Telnet ();
$t = new Net::Telnet (Timeout => 1, Errmode=>'die');
$t->open("sbr-3524-1.conpap.com");
$t->waitfor('/Password\:\s/i');
$t->print("xxxxxxx");
$t->waitfor('/SBR-3524-1\>/i');
@lines = $t->cmd("who");
print @lines;
$t->close();

The script times out at the following line:

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

I get a "command timed-out at U:\PerlScripts\test2.pl 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>

$t->waitfor('/SBR-3524-1\>/i');

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

Thanks.
1 REPLY
Highlighted
A. Clay Stephenson
Acclaimed Contributor
Solution

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:

viz:

#!/usr/bin/perl -w

use strict;

use Net::Telnet ();
my $t = new Net::Telnet (Timeout => 5, Errmode=>'die');
$t->open("sbr-3524-1.conpap.com");
$t->waitfor('/Password\: /i');
$t->print("xxxxxxx");
$t->waitfor('/SBR-3524-1\>/i');
my @lines = $t->cmd("help");
print "Lines: ",@lines,"\n";
$t->close();

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.