$ ngh bestServerEver GPG Pass : root@**********'s password: Linux **** 2.6.32-042stab059.7 #1 SMP Tue Jul 24 19:12:01 MSK 2012 x86_64 GNU/Linux motd!!!!!!!!!! Last login: Mon Feb 4 22:18:10 2013 from ******************* bash [root@******:~]$ bash [root@******:~]$ #### $ngh BestServerEver root@server# #### local (*OUT, *ERR); open OUT, ">&STDOUT"; open ERR, ">&STDERR"; close STDOUT; close STDERR; print "don't print"; open STDOUT, ">&OUT"; open STDERR, ">&ERR"; #### $exp->stty("-echo"); #### 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();