Perl Expect: For ssh login, if a bad password fails, how to try another password?

213 Views Asked by At

When using Expect in Perl to automate ssh logins, if the 1st password fails, how can we try another password?

It's not hard to find the pure Expect examples to do so but cannot find one for Expect in Perl.

use Expect;

my $bad_pwd = 'pw123';
my $good_pwd = 'pw1234';

my $exp = Expect->spawn("ssh [email protected]") or die;
$exp->expect($timeout,  [ "password: ", sub {$exp->send("$bad_pwd\n"); }]);

Thanks in advance!

0

There are 0 best solutions below