3
# see http://perlmonks.org/?node_id=890441
11
@ARGV == 3 or die <<EOU;
13
$0 host user_passwd root_passwd
21
my $ssh = Net::OpenSSH->new($host, passwd => $pass1);
22
$ssh->error and die "unable to connect to remote host: " . $ssh->error;
24
$ssh->system("sudo -K");
26
my ( $pty, $pid ) = $ssh->open2pty({stderr_to_stdout => 1}, 'sudo', -p => 'configtest:', 'bash', '-i')
27
or return "failed to attempt sudo bash: $!\n";
29
my $expect = Expect->init($pty);
32
[ qr/configtest:/ => sub { shift->send("$pass2\n"); exp_continue;} ],
33
[ qr/Sorry/ => sub { die "Login failed" } ],
34
[ qr/.*#\s+/ => sub { print shift->match }]