Date: Sat, 24 Oct 2009 18:02:16 +0100 From: Matthew Seaman <m.seaman@infracaninophile.co.uk> 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: <4AE33318.2040000@infracaninophile.co.uk> 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
This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig38A4C2AD9C859A51427CAEE2 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Paul Schmehl wrote: > --On Saturday, October 24, 2009 4:16 AM -0500 Matthew Seaman=20 > <m.seaman@infracaninophile.co.uk> wrote: >=20 >> Kelly Martin wrote: >>> Greetings, here's a simple question for the FreeBSD gurus out there. = I >>> have several servers running cron scripts daily for me, and they all >>> send me e-mail with their output. Regardless of which server it is, >>> each of these e-mails have the From: address looking exactly the same= =2E >>> They all say they are from the "Cron Daemon". Fine, but I'd like to >>> know more clearly which server the cron output is from. >>> >>> 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 immediatel= y >>> 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. >> >> Hmmm... that's actually quite tricky. There's no facility within >> cron(8) for changing the address it sends /from/, and as the bit you >> want to change is technically a comment on the From: line, and not >> the actual sender address (the bit in the <angle brackets>) all the >> address rewriting-fu in sendmail won't really help. Besides, root@...= >> is listed as a member of the 'Exposed User' class: that is, addresses >> that should be exempt from address rewriting, so you'ld also have to >> modify that. >> >> Do you control the mail server where you read your e-mail? Can you us= e >> eg. procmail(1) as a delivery agent? You should be able to match e-ma= ils >> from Cron and rewrite headers, or deliver cron e-mails into per-machin= e >> 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/std= err >> and e-mail it for you. Here's a handy shell programming trick that ca= n >> 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 bo= dy >> 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 ru= ns >> as is not the same as the 'From:' address. >> >=20 > Why not just echo `hostname` as the first line of every script? Isn't = > that what he really wants to know? >=20 > Or echo "This script came from `hostname`"? There is that, but I had assumed the idea was to be able to better distinguish the different e-mails /before/ opening them up in the MUA. Cheers, Matthew --=20 Dr Matthew J Seaman MA, D.Phil. 7 Priory Courtyard Flat 3 PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate Kent, CT11 9PW --------------enig38A4C2AD9C859A51427CAEE2 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.13 (FreeBSD) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEAREIAAYFAkrjMyAACgkQ8Mjk52CukIxF6wCfZInb5Km+bJ8sivofK4Okr45F xc8An17YZ5CQvGx0VCBYHk4s9diYenS1 =rFGB -----END PGP SIGNATURE----- --------------enig38A4C2AD9C859A51427CAEE2--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4AE33318.2040000>