salva has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I have written an script that uses Expect to perform password authentication on a SSH connection:

# initialize an Expect object: my $conn = Expect->new; $conn->raw_pty(1); # spawn a new SSH process: $conn->spawn('/usr/bin/ssh', -l => $user, $host, -s => 'sftp') or die $errstr; # wait for the password prompt: $conn->expect($timeout, "Password:") or die "Password not requested as expected"; $conn->send("$passwd\n"); # SSH echoes the "\n" after the password, remove it from the stream: $conn->expect($timeout, "\n");
and it works, but the Password: prompt still gets printed to the console. Is there any way to eliminate it?

The full source code for the script is available from here

Thanks!

Replies are listed 'Best First'.
Re: Expect & SSH
by Fletch (Bishop) on Apr 25, 2007 at 01:36 UTC

    You want to disable copying output STDOUT with $conn->log_user( 0 ) (possibly re-enabling it after you've logged in to show the output from whatever it is you're running).