scotchie has asked for the wisdom of the Perl Monks concerning the following question:
With Net::OpenSSH, I used to be able to connect without any problems using password-interactive authentication (our system administrators having conveniently blocked every other authentication method). Connecting code looks like:
my $ssh = Net::OpenSSH->new( host => $hostname, user => $Username, password => $Password, master_opts => \@ssh_opts, timeout => 10, ) || die("Cannot connect to $hostname");
However, the system administrators have recenctly decided to send me on another adventure by adding the following 2nd prompt after the password prompt:
Your password will expire in XXX days Press any key to continue.
Now Net::OpenSSH is timing out while it waits for the Enter key (CR-NL) to be sent to the terminal. I reviewed the module documentation and source code, and it appears that the code to send the password to the remote terminal is hard-coded. It looks for the colon (:) character, and then it stuffs the password onto the pty.
It was relatively easy to modify the module to deal with my specific situation, by trapping the additional prompt and sending the CR-NL sequence:
elsif ( $$bout =~ s/(.*)Press Enter to Continue//is ) { print STDERR "$1"; print $mpty "\r\n"; }
However, I was wondering, is there any way to use Expect to handle the various messages and prompts that are sent by the server before the user gets logged on?
I noticed that Net::OpenSSH has a way to get an Expect object, but I think it only works after the user is already logged on. Is there is a way to use Expect to deal with additional prompts and system-generated messages before the user gets logged on?
Is there a way to do this, or could the module be enhanced to allow it?
Thanks, Scott
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using Expect to handle Net::OpenSSH 2nd password prompt?
by salva (Canon) on Jul 12, 2011 at 09:23 UTC | |
|
Re: Using Expect to handle Net::OpenSSH 2nd password prompt?
by james2vegas (Chaplain) on Jul 11, 2011 at 23:26 UTC |