On Sat 14 Nov 2015 at 21:25:47 (-0500), Kynn Jones wrote:
> On Sat, Nov 14, 2015 at 8:36 PM, Gene Heskett <ghesk...@shentel.net> wrote:
> > On Saturday 14 November 2015 17:58:59 Kynn Jones wrote:
> >
> >> I'm trying to set up a `cron` job that will send me mail for some
> >> outputs.
> >>
> >> In my `crontab` I have the `MAILTO` variable set to my email address,
> >> as well as the directives
> >>
> >> * * * * * /bin/date >> /tmp/debug_cron
> >> * * * * * /bin/date >&2
> > On the machine, MAILTO: is not normally to your email address, but
> > usually is username@localhost.
> 
> Oh, I see.  That makes cron's mail feature significantly less
> useful/convenient than I thought.

Well, typically I wouldn't want any of my cron MAILTOs to point
outside my LAN. In fact, I find it less confusing to keep hosts' cron
missives on each host rather than centrally.

But in any case, that doesn't stop you from doing the following:

MAILTO=myself

* * * * * date >> /tmp/dated-$(date +\%F-\%R) && mutt -s $(date +\%F-\%R) -a 
/tmp/dated-$(date +\%F-\%R) -- my-inter...@email-address.example.org

Here the filename is datestamped (I don't want progressively longer
emails), and mutt sends the appropriate file as an attachment.
The -- terminates -a which introduces a *list* of files. I've used
%R to give me 60 seconds of precision. (If the time were to advance,
this scheme would fail.) It would be tidier to use one datestamp
everywhere by saving it at the start.

Alternatively you could get cron to run a normal script and do
everything in that. Just don't be caught naming your script
"script.sh" :)

Cheers,
David.

Reply via email to