From: Sreekanth P. <S.P...@ft...> - 2008-10-29 18:48:56
|
Hi, I am not able to get the send() function working in my code. Here is the code: #!/usr/local/perl5/bin/perl -w #--------------------------------------------------------------------------- # $Id$ #--------------------------------------------------------------------------- use Expect; use IO::Stty; $Expect::Exp_Internal = 1; my $file = "temp.txt"; my $timeOut = 10; my $cmd = 'sftp'; my $params = (" $user\@$host"); my $exp = new Expect; $exp->spawn($cmd,$params) or die "cannot spawn expect \n"; $exp->debug(3); $exp->log_user(1); $Expect::Debug = 3; $exp->expect($timeOut, ["Password:"]); $exp->send("$pass\r\n") or die "send pass failed: $@ \n"; $exp->expect($timeOut, ["sftp>"]) or die "sftp prompt is expected \n"; $exp->send("get $file\n"); $exp->expect($timeOut, ["sftp>"]); $exp->send("bye\n"); $exp->soft_close(); And the output is: $perl system_expect_script.perl Spawned 'sftp user@host' spawn id(3) Pid: 32344 Tty: /dev/pts/16 at /usr/lib/perl5/site_perl/5.8.5/Expect.pm line 181 Expect::spawn('Expect=GLOB(0x997f168)', 'sftp', ' user@host') called at system_expect_script.perl line 20 expect(Expect=GLOB(0x997f168) 10 ARRAY(0x99d1604)) called... expect(): handling param 'ARRAY(0x99d1604)'... Starting EXPECT pattern matching... at /usr/lib/perl5/site_perl/5.8.5/Expect.pm line 561 Expect::expect('Expect=GLOB(0x997f168)', 10, 'ARRAY(0x99d1604)') called at system_expect_script.perl line 24 spawn id(3): beginning expect. Timeout: 10 seconds. Current time: Wed Oct 29 17:54:00 2008 spawn id(3): list of patterns: #1: -re `Password:' spawn id(3): Does `' match: pattern #1: -re `Password:'? No. Waiting for new data (10 seconds)... spawn id(3): new data. spawn id(3): read 31 byte(s). Connecting to host... spawn id(3): Does `Connecting to host...\r\n' match: pattern #1: -re `Password:'? No. Waiting for new data (9 seconds)... spawn id(3): new data. spawn id(3): read 10 byte(s). Password: spawn id(3): Does `Connecting to host...\r\nPassword: ' match: pattern #1: -re `Password:'? YES!! Before match string: `Connecting to host...\r\n' Match string: `Password:' After match string: ` ' Matchlist: () Returning from expect successfully. spawn id(3): accumulator: ` ' Sending 'password\r\n' to spawn id(3) at /usr/lib/perl5/site_perl/5.8.5/Expect.pm line 1264 Expect::print('Expect=GLOB(0x997f168)', 'password\x{d}\x{a}') called at system_expect_script.perl line 33 send pass failed: Closing spawn id(3). at /usr/lib/perl5/site_perl/5.8.5/Expect.pm line 1431 Expect::hard_close('Expect=GLOB(0x997f168)') called at /usr/lib/perl5/site_perl/5.8.5/Expect.pm line 1621 Expect::DESTROY('Expect=GLOB(0x997f168)') called at system_expect_script.perl line 0 eval {...} called at system_expect_script.perl line 0 spawn id(3) closed. Pid 32344 of spawn id(3) terminated, Status: 0x100 Please let me know if I am missing anything Thanks in advance - Sreekanth |