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 user@example.com") or die;
$exp->expect($timeout, [ "password: ", sub {$exp->send("$bad_pwd\n"); }]);
Thanks in advance!