From owner-freebsd-questions@FreeBSD.ORG Sat Oct 24 16:11:41 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 06AC3106566B for ; Sat, 24 Oct 2009 16:11:41 +0000 (UTC) (envelope-from prvs=541daa370=pschmehl_lists@tx.rr.com) Received: from ip-relay-001.utdallas.edu (ip-relay-001.utdallas.edu [129.110.20.111]) by mx1.freebsd.org (Postfix) with ESMTP id C9AA08FC19 for ; Sat, 24 Oct 2009 16:11:40 +0000 (UTC) X-Group: RELAYLIST X-IronPort-AV: E=Sophos;i="4.44,617,1249275600"; d="scan'208";a="20542277" Received: from smtp3.utdallas.edu ([129.110.20.110]) by ip-relay-001.utdallas.edu with ESMTP; 24 Oct 2009 10:42:36 -0500 Received: from [10.0.0.20] (cpe-76-182-207-101.tx.res.rr.com [76.182.207.101]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp3.utdallas.edu (Postfix) with ESMTPSA id DFDB34EF37; Sat, 24 Oct 2009 10:42:36 -0500 (CDT) Date: Sat, 24 Oct 2009 10:42:27 -0500 From: Paul Schmehl To: Matthew Seaman , Kelly Martin Message-ID: In-Reply-To: <4AE2C5F4.20109@infracaninophile.co.uk> References: <1338880b0910240008h5d5e7846q8ccf184728d9e036@mail.gmail.com> <4AE2C5F4.20109@infracaninophile.co.uk> X-Mailer: Mulberry/4.0.8 (Win32) X-Munged-Reply-To: Figure it out MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Cc: FreeBSD Questions Subject: Re: changing cron's From: address in emails X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Paul Schmehl List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 24 Oct 2009 16:11:41 -0000 --On Saturday, October 24, 2009 4:16 AM -0500 Matthew Seaman wrote: > 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. >> 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 immediately >> obvious to me how to change the From: field. Already the subject line >> says something like "Cron ..." 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 ) 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 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 $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 > echo "To: > 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`"? Paul Schmehl As if it wasn't already obvious, my opinions are my own and not those of my employer.