sub interactiveSsh { my ($pConfig,$pass)=@_; my $exp = new Expect; $exp->slave->clone_winsize_from(\*STDIN); $exp->spawn("ssh root\@".$pConfig->{'host'}); my $spawn_ok; $exp->expect(40, [ qr'(yes/no)', sub { my $fh = shift; $fh->send("yes\n"); exp_continue; } ], [ qr'assword:', sub { if ($spawn_ok) { $exp->interact(); } my $fh = shift; $fh->send("$pass\n"); $spawn_ok=1; exp_continue; } ], [ qr'#', sub { my $fh = shift; $fh->send("bash\n"); $exp->send("stty -echo\n"); $exp->interact(); exp_continue; } ], [ eof => sub { if ($spawn_ok) { print BOLD GREEN, "SSH close connexion to ".$pConfig->{'host'}.".\n", RESET; exit 0; } else { die "ERROR: could not spawn ssh.\n"; } } ], [ timeout => sub { die "No login.\n"; } ], '-re', qr'[#>:] $', ); $exp->interact();