Re: Accessing output of command spawned by Expect SOLVED
From: Bill Barnett (spam.me.not_at_fuse.net)
Date: 03/08/04
- Next message: Randy W. Sims: "Re: PPM Module for DB:Oracle"
- Previous message: Stuart White: "Re: listing prime numbers in a range (Beginning Perl exercise)"
- In reply to: Bill Barnett: "Accessing output of command spawned by Expect"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 8 Mar 2004 10:23:18 -0800
I have solved my own problem (with thanks to Doug Hogan for his
excellent pointers) and provide the solution below for the group's
benefit.
spam.me.not@fuse.net (Bill Barnett) wrote in message news:<993bc84e.0403051046.2000ca1@posting.google.com>...
> Hello all,
>
> I am mirroring a cvs repository using rsync via a passphrase
> authenticated ssh connection. The script I have written to perform the
> synchronization is run periodically as a cron task and is functioning as
> desired with the following exception.
>
> I would like to capture the verbose output of the rsync command and send
> it as the body of an e-mail message. The script uses Expect to pass in
> the passphrase then run rsync. I have seen documentation concerning the
> use of 'expect_out' but when I call it Perl complains about it being an
> "unknown method". (I'm using Expect 1.15, I believe, and Perl 5.8.1.)
>
> I have run the script using the Perl debugger in an attempt to determine
> where I can gain access to the desired output but due to my
> unfamiliarity with Expect I am soon lost in the subroutine calls. The
> sanitized script is below. Any comments/fixes/suggestions are appreciated.
>
> Thanks,
>
> Bill
[SNIP]
> $command = Expect->spawn("rsync -avz --delete --force " . $source . " "
> . $destination) or ($body .= "\nCould not spawn rsync!\n");
> $response = $command->expect(15, "passphrase");
> if ($response) {
>
> $command->send($pwd . "\r");
> $command->expect(undef, $prompt);
> # $body .= $command->expect_out('buffer');
> $command->soft_close();
>
> } else {
>
> $body .= "\nNo passphrase prompt received from rsync!\n";
>
> }
Replace the previous lines of code from the original post with those
given below.
$command = new Expect();
$command->spawn("rsync", @rsync_params) or ($body .= "\nCouldn't start
rsync!\n");
$response = $command->expect(15, '-re', $prompt);
if ($response) {
$command->send($pwd . "\r\n");
my (undef, undef, undef, $rsync_return, undef) =
$command->expect(undef, $prompt);
$body .= $rsync_return;
$command->soft_close();
} else {
$body .= "\nNo passphrase prompt received from rsync!\n";
}
- Next message: Randy W. Sims: "Re: PPM Module for DB:Oracle"
- Previous message: Stuart White: "Re: listing prime numbers in a range (Beginning Perl exercise)"
- In reply to: Bill Barnett: "Accessing output of command spawned by Expect"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|