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; } ], );
In reply to Need some pointers using Expect.pm by TASdvlper
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |