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..)$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");
What am I still doing wrong? Thanks!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
In reply to Expect question by RaduH
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |