From: Hailey N. <Hai...@Su...> - 2003-10-01 20:33:58
|
Hi Chris, Thanks so much for the help! I was able to telnet into the hostA then the next one it keeps looping around the statement below and won't quit. If I take out the "\n"" character it won't loop but it won't go further either. $fh->send("telnet $hostsB\n"; Help Help Help ... thanks again. H ----------- !/bin/perl use Expect; $Expect::Log_Stdout = 1; # variables define here # ... my $exp = Expect->spawn("telnet $hostA") or die "Cannot spawn telnet: $!\n"; my $spawn_ok; $exp->log_file("testlog"); $exp->expect($timeout, [ qr'login: $', sub { $spawn_ok = 1; my $fh = shift; $fh->send("$username\n"); exp_continue; } ], [ 'Password: $', sub { my $fh = shift; print $fh "$password\n"; exp_continue; } ], [ '# $', sub { $spawn_ok = 1; my $fh = shift; $fh->send("telnet $hostB\n"); <================ exp_continue; } ], [ 'login: $', sub { my $fh = shift; print $fh "$username\n"; exp_continue; } ], [ 'Password: $', sub { my $fh = shift; print $fh "$password\n"; exp_continue; } ], [ eof => sub { if ($spawn_ok) { die "ERROR: premature EOF in login.\n"; } else { die "ERROR: could not spawn telnet.\n"; } } ], [ timeout => sub { die "No login.\n"; } ], '-re', qr'[#] $' # wait for shell prompt, then exit expect ); $exp->hard_close(); ------------------------- > > First you will have to login to A. That involves what you have, plus you > will have to $exp->expect() for whatever telnet responds with when it > asks for the password. Then use a $exp->send() to send the password. > Then $exp->expect() for the prompt on A. Once you are logged into A, use > a $exp->send() to call telnet $B on A to login to B, $exp->expect() for > the password prompt, and then $exp->send() it. Once logged into B, do > the same to login to C, and the same for D, and the same for ... > > -Chris > > > On 10/1/03 at 11:07 AM Hailey Nguyen wrote: > >> Hi, >> >> Please show me how to do nested telnet sessions using Expect.pm module? >> >> 1- telnet to machine A >> 2- from A to mcahine B >> 3- from M to another machine C >> >> ----- >> use Expect; >> >> my $exp = Expect->spawn("telnet $somehost") >> or die "Cannot spawn telnet: $!\n"; >> >> ... >> >> ----- >> Your help is greatly appreciated. Please reply directly to me since >> I am not on the alias. >> >> Hailey. >> >> > |