I've written a wrapper program for mailx using perl that allows me to easily add attachments and do some other nifty things that were a little frustrating to accomplish with mailx.
In the first few lines I have:
use strict;
use warnings;
use Getopt::Long;
my ( $to, $from, $subject, $attachments, $body, $file ) = (undef) x 7;
GetOptions(
"to=s" => \$to,
"from=s" => \$from,
"subject=s" => \$subject,
"attachments=s" => \$attachments,
"body=s" => \$body,
"file=s" => \$file,
);
$to = getlogin unless $to;
$from = getlogin unless $from;
$subject = " " unless $subject;
This wrapper up until now has worked fine when being called by other scripts. However now that we have a script being run by the Cron some funny things are happening. This Cron job calls the wrapper by only specifying -t and -su but omitting -fr (yes abbreviations of the flags are being used). The resulting email correctly sets the To: however has the Sender listed as [email protected] with the subject line blank. As per the above code I can only assume that there is something strange going between Cron and the Getopt::Long module. Does anyone know why a Cron job may cause this odd behavior? If it is something else that is wrong what would it be?