From: Bryan C. <co...@od...> - 2007-03-20 18:43:33
|
Brad and Austin, =20 I've finally figured this thing out (sort of). Expect works fine in a "normal" environment. =20 We have a utility built in-house that we use to log the output of our scripts. That utility does some forking, redirection of stdin & stdout, and unbuffering before I make my Expect call. Between the two modules, there's just one too many redirects or something. I'm not sure if I'll ever get it sorted out to the point where I can make them work together, but they work fine independently. =20 I've appreciated your help, and hope I can return the favor some time. =20 Bryan ________________________________ From: btr...@gm... [mailto:btr...@gm...] On Behalf Of Bradford Ritchie Sent: Thursday, March 15, 2007 9:07 PM To: Bryan Cox Cc: exp...@li... Subject: Re: [Expectperl-discuss] Expect.pm & sftp Bryan, Looking at your code more closely, have you tried replacing qr/$_sftp_prompt/ with a literal string like qr/myprompt%/ or 'myprompt' ? Might be worth a try since the other two expect lines seem to be succeeding for you. =20 Also, not that it matters, but I noticed that in sub that handles the password, you define $exp_self to hold the expect object instance, but then call $self->verbose(). Wasn't this giving you errors? On 3/15/07, Bryan Cox <co...@od...> wrote:=20 Thanks, Austin! =09 I copied your script verbatim, and it works. However, it doesn't make any difference whether I include the space after the prompt or not. It works in either case. ( Well, the space is included in $sftp->before(), but that's beside the=20 point. ) =09 So now I'll start turning your script into mine incrementally until it breaks. =09 I'll let you know what I discover. =09 Bryan =09 -----Original Message----- From: Austin Schutz [mailto: te...@of...] Sent: Thursday, March 15, 2007 2:40 PM To: Bryan Cox Cc: Bradford Ritchie; exp...@li...=20 Subject: Re: [Expectperl-discuss] Expect.pm & sftp =09 On Wed, Mar 14, 2007 at 02:27:17PM -0700, Bryan Cox wrote: > Here's an update: > > I've tried sftp, ftp, and rlogin. All fail in the same way:=20 > > -> spawn id(4): Does `' > -> match: > -> pattern #1: -re `(?-xism:ame.*:)'? No. > -> pattern #2: -re `(?-xism:assword:)'? No. > -> pattern #3: -re `(?-xism:ftp>)'? No.=20 > -> pattern #4: -re `(?-xism:(\n)|(\r))'? No. > -> Waiting for new data (10 seconds)... > -> TIMEOUT > =09 This may be failing because of a race condition. You are not waiting for a space after 'sftp>'. I have a simple script I was able to use to get a listing of files from sftp, so I don't think sftp itself is doing anything odd: =09 #!/usr/bin/perl use Expect;=20 =09 # usage: test.pl <[username@]host> <password> =09 $sftp =3D Expect->spawn('sftp ' . $ARGV[0]); $sftp->exp_internal(1); $sftp->expect(10, 'ord: '); print $sftp $ARGV[1]."\r"; $sftp->expect(10,=20 'sftp> '); print $sftp "ls\r"; $sftp->expect(10, 'sftp> '); print "Files:" . $sftp->before(); =09 It's important to make sure you have received all the output=20 from the remote host before sending it anything. It may flush its buffers before reading, thereby dumping whatever you thought you sent it. =09 Austin =09 |