in reply to Re^3: Losing my mind with Net::OpenSSH and Expect
in thread Losing my mind with Net::OpenSSH and Expect
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();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Losing my mind with Net::OpenSSH and Expect
by rastoboy (Monk) on Mar 01, 2011 at 20:48 UTC | |
by salva (Canon) on Mar 02, 2011 at 09:46 UTC | |
by rastoboy (Monk) on Mar 03, 2011 at 18:29 UTC | |
by rastoboy (Monk) on Mar 06, 2011 at 18:53 UTC |