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

I'm afraid switching to another module is not an option at this stage .. (none of the modules above are installed with our program)
  • Comment on Re^2: How to catch/avoid SSHConnectionAborted

Replies are listed 'Best First'.
Re^3: How to catch/avoid SSHConnectionAborted
by salva (Canon) on Nov 15, 2010 at 15:39 UTC
    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; }
      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"; } }
Re^3: How to catch/avoid SSHConnectionAborted
by mjscott2702 (Pilgrim) on Nov 15, 2010 at 15:24 UTC
    What are the contents of the $login_output variable?

    According to the Net::SSH::Expect manpage, it should contain some form of response from the server:

    # 2) logon to the SSH server using those credentials. # test the login output to make sure we had success my $login_output = $ssh->login(); if ($login_output !~ /Welcome/) { die "Login has failed. Login output was $login_output"; }

      The $login_output variable only contains the prompt for password: Password: I think its contents is installation dependent.