Hi Monks,
Here's the piece of code I have trouble with:
$sftp = Expect->spawn("sftp $toyName\@$targetServer") || die("Coul +dn't spawn sftp, $!"); $sftp->expect(5, "Password: ") || die("Never got password prompt +on $targetServer, ".$sftp->exp_error()."\n"); print($sftp "$toyPassword\r"); $sftp->expect(5, "sftp\> ") || die("Never got sftp prompt on $targ +etServer, ".$sftp->exp_error()."\n"); print ($sftp "put $backupFileName\r"); $sftp->expect(120, "sftp> ") || die("Never got password prompt on +$targetServer after upload, ".$stfp->exp_error()."\n");
I read the documentation in the Expect module and I saw it can be (well, IS) very strict when it comes to matching the expected strings and the "Password: " string is one particular example being discussed. They warn about the exact number of blank spaces to expect after the colon. I was careful with all of these but I still cannot match the "Password: " prompt (two blanks after : on purpose..)
Here's the resulting output:
Spawned 'sftp user@<host_ip>' spawn id(3) Pid: 23271 Tty: /dev/pts/2 at /usr/lib/perl5/site_perl/5.8.8/Expect.pm line 181 Expect::spawn('Expect', 'sftp user@<host_ip>') called at lifch.p +l line 126 main::upgrade_procedure() called at lifch.pl line 267 expect(Expect=GLOB(0xb96b40) 5 Password: ) called... expect(): handling param 'Password: '... expect(): exact match 'Password: '... Starting EXPECT pattern matching... at /usr/lib/perl5/site_perl/5.8.8/Expect.pm line 561 Expect::expect('Expect=GLOB(0xb96b40)', 5, 'Password: ') called + at lifch.pl line 127 main::upgrade_procedure() called at lifch.pl line 267 spawn id(3): beginning expect. Timeout: 5 seconds. Current time: Fri Oct 26 17:04:42 2007 spawn id(3): list of patterns: #1: -ex `Password: ' spawn id(3): Does `' match: pattern #1: -ex `Password: '? No. Waiting for new data (5 seconds)... spawn id(3): new data. spawn id(3): read 33 byte(s). spawn id(3): Does `Connecting to <host_ip>...\r\n' match: pattern #1: -ex `Password: '? No. Waiting for new data (5 seconds)... spawn id(3): new data. spawn id(3): read 10 byte(s). spawn id(3): Does `Connecting to <host_ip>...\r\nPassword: ' match: pattern #1: -ex `Password: '? No. Waiting for new data (4 seconds)... TIMEOUT Returning from expect with TIMEOUT or EOF Never got password prompt on <host_ip>, 1:TIMEOUT Closing spawn id(3). at /usr/lib/perl5/site_perl/5.8.8/Expect.pm line 1431 Expect::hard_close('Expect=GLOB(0xb96b40)') called at /usr/lib/p +erl5/site_perl/5.8.8/Expect.pm line 1621 Expect::DESTROY('Expect=GLOB(0xb96b40)') called at lifch.pl line + 0 eval {...} called at lifch.pl line 0 spawn id(3) closed. Pid 23271 of spawn id(3) terminated, Status: 0x100
What am I still doing wrong? Thanks!

In reply to Expect question by RaduH

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.