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

my perl code
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
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:
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:
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:
Sent password! Sent session reason! Finished processing login expect expUXstatus[2]
I Does anyone have any suggestions? Thanks!


In reply to Issue with Expect by azstyx

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.