azstyx has asked for the wisdom of the Perl Monks concerning the following question:
Hello Folks!
Env=SUSE 10.2 Linux, Perl 5.14.2, Expect v1.21
I am trying to use Expect to ssh to a Solaris 8 server.
The manual dialog for this login is:
>ssh -o StrictHostkeyChecking=no user@sol8server Could not create directory '/appl/user/.ssh'. Failed to add the host to the list of known hosts (/appl/user/.ssh/known_hosts). user@sol8server's password: <== I enter password here Last login: Tue Mar 20 10:01:13 2012 from xxx Could not chdir to home directory /home/user: No such file or directory **** SYSTEM ACTIVITIES MAY BE MONITORED **** <== sol 8 server What is the purpose of this session: <== sol 8 server Collect data. <== my response Thanks, have a fine day and be sure log off after you are done. <== sol 8 server sol8server% <== sol 8 server
The above executes OK for password prompt and it also catches the prompt for the reason for the login ok. Then I send the reason "Get configs\r". This is where it stops working - it appears that it did not get the reason string. Nothing is sent back after I send the reason string - I can see this in the expect logfile:my $expPty = 1; # pty mode my $expDebug = 3; # Expect debug level $sshUX = Expect->new; # create Expect object $sshUX->debug($expDebug); # debugging $sshUX->log_file($expUXLogFile, "w"); $sshUX->raw_pty($expPty); $sshUX->expect(10, [qr /password: $/ => # got password prompt sub { my $self = shift; $self->send("$passw\r"); print "Sent password!\n";#debug exp_continue; } # end sub ], [qr /session:\n$/ => # got reason prompt sub { my $self = shift; $self->send("Get configs\r"); print "Sent session reason!\n";#debug exp_continue; } # end sub ], # Timeout trap [timeout => sub { $expUXStatus = 1; print PL "Error,Timeout while waiting $expTimeOut secs for login on [$UXHost] user[$usr]. Error:" . $sshUX->exp_error() . "\n"; } ], # EOF trap [eof => sub { $expUXStatus = 2; print PL "Error,Premature EOF during login for [$UXHost] user[$usr]. Error:" . $sshUX->exp_error() . "\n"; } ], '-re', qr /%$/, # wait for device prompt '%' ); # End expect for Login processing print "Finished processing login expect expUXstatus[$expUXStatus]\n"; # debug
All I get is a timeout and it appears that the system never responds after i send the "Get Configs" string with carriage return. Ends execution with printing:Could not create directory '/appl/user/.ssh'. Failed to add the host to the list of known hosts (/appl/user/.ssh/known_hosts). user@sol8server's password: Last login: Tue Mar 20 09:45:08 2012 from xxx Could not chdir to home directory /home/user: No such file or directory **** SYSTEM ACTIVITIES MAY BE MONITORED **** What is the purpose of this session:
I Does anyone have any suggestions? Thanks!Sent password! Sent session reason! Finished processing login expect expUXstatus[2]
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Issue with Expect
by jffry (Hermit) on Mar 21, 2012 at 20:05 UTC | |
by azstyx (Acolyte) on Mar 22, 2012 at 01:11 UTC | |
by azstyx (Acolyte) on Mar 22, 2012 at 15:39 UTC | |
by zengargoyle (Deacon) on Mar 23, 2012 at 03:45 UTC | |
by azstyx (Acolyte) on Mar 23, 2012 at 20:32 UTC |