#!/usr/bin/env perl
# send mail to the specified address if standard input contains lines of input
# $Id$
if (@ARGV < 1)
{
print STDERR "Usage: mailifnotempty
[]\n";
exit 2;
}
my $address = shift @ARGV;
my $subject = shift @ARGV;
if (!eof(STDIN))
{
my $command = '/usr/bin/mail';
if (defined($subject))
{
$command .= sprintf ' -s "%s"', $subject;
}
if (defined($address))
{
$command .= sprintf ' "%s"', $address;
}
open(PIPE, "|$command")
or die "Cannot invoke $command";
while ($line = )
{
print PIPE $line;
}
close PIPE;
}