[SunHELP] Emailing cron output

Will Mc Donald wmcdonald at ntlworld.com
Thu May 1 09:14:08 CDT 2003


From: "Songonuga Tope" <Tope.Songonuga at thetube.com>
> Hi gurus
>
> I'm having a little trouble with emailing the output of a shell script
<snip>
> $ mailx username at xx.com < /tmp/outputfile.txt (full contents
> are emailed)
> $./test.sh > /tmp/outputfile.txt | mailx username at xx.com <
> /tmp/outputfile.txt  (only the output of the 1st command are emailed, just
> half the contents of the actual outputfile.txt)

Just pipe the output straight into mailx, don't mess about with the output
file in between...

$ ./test.sh | mailx -s 'test.sh output' user at domain.com

If you need to have that output file then you should probably separate the
steps like either of the following...

$./test.sh > /tmp/outputfile.txt; mailx user at domain.com < /tmp/outputfile.txt
(Execute the command(s) before the ';' then the next command(s).)

$./test.sh > /tmp/outputfile.txt && mailx user at domain.com <
/tmp/outputfile.txt
(Execute the first command(s), then, if successful the second set of
command(s))

Though, thinking about it the first of those is probably preferable since the
second choice would only mail you on successful completion of the test.sh and
ideally you'd want to be emailed the output if it exited with an error code
too.

Will.



More information about the SunHELP mailing list