TASdvlper has asked for the wisdom of the Perl Monks concerning the following question:
I'm new to using Perl's Expect module so maybe I'm going about this the wrong way. Basically, with the code below i'm trying to login, run a script and exit. But, because the 1st thing that is returned from a telnet is "Trying aaa.bb.ccc.ddd ... " and my script gets stuck in a endless loop. Any pointers ?
use strict; use warnings; use Expect; $Expect::Exp_Internal = 1; my $my_login = "xxx"; my $my_password = "yyy"; my $timeout = "5"; #Spawn a Telnet Process to connect to a build machine. my $exp = Expect->spawn("telnet aaa.bb.ccc.ddd") or die "Cannot Spawn Telnet...exiting\n"; #Send user name a password. $exp->expect($timeout, [ qr/^login:\s+$/i, sub { my $self = shift; $self->send("$my_login\n"); exp_continue; } ], [ qr/^password:\s+$/i, sub { my $self = shift; $self->send("$my_password\n"); exp_continue; } ], # [ qr/.*/i, sub { my $self = shift; # $self->send("/sean/test.pl\n"); # i exp_continue; } ], [ qr/^COMPLETE.*$/i, sub { my $self = shift; $self->send("exit\n"); exit; } ], [ qr/.*/i, sub { my $self = shift; exp_continue; } ], );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Need some pointers using Expect.pm
by waswas-fng (Curate) on Dec 03, 2003 at 23:16 UTC | |
by TASdvlper (Monk) on Dec 03, 2003 at 23:23 UTC | |
by waswas-fng (Curate) on Dec 03, 2003 at 23:36 UTC |