in reply to Losing my mind with Net::OpenSSH and Expect
Can you try it?#!/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 +; my ( $pty, $pid ) = $ssh->open2pty("sudo -kp 'configtest:' bash 2>&1") or return "failed to attempt sudo bash: $!\n"; my $expect = Expect->init($pty); $expect->expect(2, [ qr/configtest:/ => sub { my $expect =shift; $expect->send($p +ass2 . "\n"); exp_continue;} ], [ qr/Sorry/ => sub { my $expect=shift; print "Failed\n"; e +xp_continue; } ], ); $expect->interact();
Which OpenSSH version and OS are you using?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Losing my mind with Net::OpenSSH and Expect
by rastoboy (Monk) on Feb 28, 2011 at 23:54 UTC | |
by rastoboy (Monk) on Mar 01, 2011 at 00:58 UTC | |
by salva (Canon) on Mar 01, 2011 at 09:37 UTC | |
by rastoboy (Monk) on Mar 01, 2011 at 20:48 UTC | |
by salva (Canon) on Mar 02, 2011 at 09:46 UTC | |
|