Hi Andreas,
2007/1/19, Andreas Brillisauer - Hetzner Online AG
<[EMAIL PROTECTED]>:
Hello,
I'm just writing a script that gets an email from stdin. This mail
should be passed to procmail via ssh. If calling ssh or procmail fails,
the mail should be saved locally.
First I tried to solve this with "system" or "open". But I cannot pipe
the mail to ssh when using "system". "open" can handle a pipe to ssh but
doesn't return the return value of ssh.
So I tried to create a pipe by my own using "pipe". After that I call
"fork". Then the mail is passed to ssh via the created pipe. But this
doesn't work.
Here is my current version of the script. For debugging reasons I call
"cat" instead of "ssh". But I get no output.
---8<---------------------------------------------------------------------
#!/usr/bin/perl
my $lb = $/;
$/ = undef;
my $mail = <STDIN>;
$/ = $lb;
my $pid;
pipe(READ, WRITE);
$pid = fork();
if ($pid == 0) {
close(WRITE);
exec('cat');
exit(1);
}
elsif ($pid > 0) {
close(READ);
my $old_handle = select(WRITE);
$| = 1;
print WRITE $mail;
waitpid($pid, WNOHANG);
$retval = $? >> 8;
select($old_handle);
print "$retval\n";
}
---8<---------------------------------------------------------------------
I would suggest you using Net::SFTP[1] to transfer the file to remote
host, and then Net::SSH::Perl[2] to invoke procmail on remote host. I
think it is the best start, then you could improve it.
[1] http://search.cpan.org/~dbrobins/Net-SFTP-0.10/lib/Net/SFTP.pm
[2] http://search.cpan.org/~dbrobins/Net-SSH-Perl-1.30/lib/Net/SSH/Perl.pm
HTH!
--
Igor Sutton Lopes <[EMAIL PROTECTED]>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/