Date: Sat, 24 Oct 2009 12:27:24 -0500 From: Kevin Kinsey <kdk@daleco.biz> To: Paul Schmehl <pschmehl_lists_nada@tx.rr.com> Cc: Kelly Martin <kellymartin@gmail.com>, FreeBSD Questions <freebsd-questions@freebsd.org> Subject: Re: changing cron's From: address in emails Message-ID: <4AE338FC.4030508@daleco.biz> In-Reply-To: <D79559A491F151EA3B0703A4@[10.0.0.20]> References: <1338880b0910240008h5d5e7846q8ccf184728d9e036@mail.gmail.com> <4AE2C5F4.20109@infracaninophile.co.uk> <D79559A491F151EA3B0703A4@[10.0.0.20]>
next in thread | previous in thread | raw e-mail | index | archive | help
Paul Schmehl wrote:
> --On Saturday, October 24, 2009 4:16 AM -0500 Matthew Seaman
> <m.seaman@infracaninophile.co.uk> wrote:
>
>> Kelly Martin wrote:
>>>
>>> How can I change the From: address of these emails to "Myserver Cron
>>> Daemon" instead? I know cron runs as the user, so it's not immediately
>>> obvious to me how to change the From: field. Already the subject line
>>> says something like "Cron <root@Myserver> ..." but this doesn't stand
>>> out enough for my tired eyes.
>>
>> Do you control the mail server where you read your e-mail? Can you use
>> eg. procmail(1) as a delivery agent? You should be able to match e-mails
>> from Cron and rewrite headers, or deliver cron e-mails into per-machine
>> mailboxes. Something like this:
>>
>> :0 h
>> * From:.*Cron <root@\/[^\.]+
>> $MATCH
>>
>> The other alternative is to re-write the cron scripts to send e-mail
>> themselves, rather than relying on cron(8) to capture their stdout/stderr
>> and e-mail it for you. Here's a handy shell programming trick that can
>> make that easier. Somewhere near the top of the script, you can add
>> something like this:
>>
>> exec 2>&1 | /usr/sbin/sendmail -oi -t
>> echo "From: Sender Name <sender@add.ress>
>> echo "To: <recipient@some.where>
>> echo "Subject: e-mail from cron job"
>> echo ""
>>
>> Then everything you print out in the script will be captured as the body
>> of the e-mail and sent to the specified recipient. You might get some
>> warnings about forgery in the mail headers if the userid the script runs
>> as is not the same as the 'From:' address.
>>
>
> Why not just echo `hostname` as the first line of every script? Isn't
> that what he really wants to know?
>
> Or echo "This script came from `hostname`"?
Or, on a related note, why have cron(8) do any mailing at all?
Most/all of my management scripts compile a mail message in
/tmp and then send it as the body of a message with mail(1),
so I can have whatever subject header I want, and the envelope
data comes from the user ("usually me@myhost.tld"). Cron sees
nothing because stdout/err is redirected to dev/null.
Kevin Kinsey
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4AE338FC.4030508>
