in reply to Re^2: How to catch/avoid SSHConnectionAborted
in thread How to catch/avoid SSHConnectionAborted

Try adding the following arguments to the constructor:
ssh_option => 'o NumberOfPasswordPrompts=1'
That should avoid the connection error being delayed, though you may also need to run some dummy command after it to let the module detect the closed SSH pipe:
my $ssh; foreach (1..3) { $ssh = eval { my $try = Net::SSH::Expect->new( host => $host, password => $password, user => $user, raw_pty => 1, timeout => 3, binary => $ssh_exec, ssh_option => 'o NumberOfPasswordPrompts=1' ); $try->exec("stty raw -echo"); $try; }; last if $ssh; sleep 1; }

Replies are listed 'Best First'.
Re^4: How to catch/avoid SSHConnectionAborted
by daphnaw (Acolyte) on Nov 16, 2010 at 10:25 UTC
    didnt work :-( It now fails on the login line with the following exception: FIX: .ssh/known_hosts SSHProcessError The ssh process was terminated. at test.pl line 775 However, the following code will catch the exception:
    my $ssh; foreach (1..3) { eval { $ssh = Net::SSH::Expect->new( host => $host, password => $password, user => $user, raw_pty => 1, timeout => 3, binary => $ssh_exec, ); }; last if $ssh; sleep 1; } die "Could not connect to remote host '$host'\n" if not $ssh; my $login_output = $ssh->login; $ssh->exec("stty raw -echo"); my $resp_uname; eval { $resp_uname = $ssh->exec('uname'); }; if ($@) { if ($@ =~ m{SSHConnectionAborted}) { die "Invalid username and/or password for OS user $user on th +e remote server!"; }else { die "Could not connect to remote host '$host' : $@\n"; } }