I had had issues trying to include the -k in the sudo command
The -k switch may be a recent addition to sudo not yet available in the version you have installed.
and it does seem to work except that I have to hit Enter for it to go into interactive mode
You are already in interactive mode but you don't notice it because Expect is eating the shell prompt. Try the following script:
#!/usr/bin/perl use strict; use warnings; use Net::OpenSSH; use Expect; my $host = $ARGV[0]; my $pass1 = $ARGV[1]; my $pass2 = $ARGV[2]; my $ssh = Net::OpenSSH->new($host, passwd => $pass1); $ssh->error and die "unable to connect to remote host: " . $ssh->error +; $ssh->system("sudo -K"); my ( $pty, $pid ) = $ssh->open2pty({stderr_to_stdout => 1}, 'sudo', -p + => 'configtest:', 'bash', '-i') or return "failed to attempt sudo bash: $!\n"; my $expect = Expect->init($pty); $expect->expect(2, [ qr/configtest:/ => sub { shift->send("$pass2\n"); ex +p_continue;} ], [ qr/Sorry/ => sub { die "Login failed" } ], [ qr/.*#\s+/ => sub { print shift->match }] ) or die "Timeout!"; $expect->interact();
In reply to Re^4: Losing my mind with Net::OpenSSH and Expect
by salva
in thread Losing my mind with Net::OpenSSH and Expect
by rastoboy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |