Your regexes are probably not doing what you expect them to. You're using 
character classes, so it's waiting for the device to return a one character 
prompt that matches any one of the characters from the class. Try something 
like /password[: ]*$/i and something similar for other prompts.

> All,
>
> I'm trying to write a perl script that will telnet a device and run one
> of two commands based on the output from a beginning command. I'm still
> in the beginning stages of this, and right now I'm simply trying to
> print the output from the device to standard out. Reading the
> documentation on Net::Telnet, it should be as easy as something like
> this:
>
> @lines = $t->print("who");
> print @lines;
>
> But when I try something similar, my array appears to simply contain the
> number '1', as if something were returning true.
>
> Here the full script I'm working on now (names have been changed to
> protect the innocent):
>
> #!/usr/bin/perl -w
> # $Id$
>
> use warnings;    # or -w above
> use strict;
>
> use Net::Telnet;
>
> my $t = Net::Telnet->new( Timeout => 10);
> my $address = '10.10.10.1';
> my @output;
>
> #print "I'm telnetting to $address.\n";
> $t->open($address);
> print "Telnetting to  $address\n";
> $t->waitfor('/[Password:]/');
> print "Logging in\n";
> $t->print('password');
> $t->waitfor('/[hostname>]/');
> @output = $t->print('who');
> $t->waitfor('/[hostname>]/');
> $t->print('exit');
> print "Logged out\n";
> print @output;
> exit;
>
> And here's the output I'm getting:
>
> Telnetting to  10.10.10.1
> Logging in
> Logged out
> 1
>
> What's going on here? Am I doing something wrong?
>
> Tim Huffman
> Network Administrator
> Kruger Communications
> Office: 630-281-7100 ext. 335
> Fax: 630-986-2495
> Email: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to