From owner-freebsd-questions@FreeBSD.ORG Sat Oct 24 17:49:13 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 315BC106568F for ; Sat, 24 Oct 2009 17:49:13 +0000 (UTC) (envelope-from kdk@daleco.biz) Received: from ezekiel.daleco.biz (southernuniform.com [66.76.92.18]) by mx1.freebsd.org (Postfix) with ESMTP id AC7DB8FC1C for ; Sat, 24 Oct 2009 17:49:12 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by ezekiel.daleco.biz (8.14.3/8.14.2) with ESMTP id n9OHlpei089093; Sat, 24 Oct 2009 12:48:06 -0500 (CDT) (envelope-from kdk@daleco.biz) X-Virus-Scanned: amavisd-new at daleco.biz Received: from ezekiel.daleco.biz ([127.0.0.1]) by localhost (ezekiel.daleco.biz [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 2mS06UU94P97; Sat, 24 Oct 2009 12:46:15 -0500 (CDT) Received: from archangel.daleco.biz (ezekiel.daleco.biz [66.76.92.18]) by ezekiel.daleco.biz (8.14.3/8.14.3) with ESMTP id n9OHRO5n088820; Sat, 24 Oct 2009 12:27:50 -0500 (CDT) (envelope-from kdk@daleco.biz) Message-ID: <4AE338FC.4030508@daleco.biz> Date: Sat, 24 Oct 2009 12:27:24 -0500 From: Kevin Kinsey User-Agent: Thunderbird 2.0.0.23 (X11/20090929) MIME-Version: 1.0 To: Paul Schmehl References: <1338880b0910240008h5d5e7846q8ccf184728d9e036@mail.gmail.com> <4AE2C5F4.20109@infracaninophile.co.uk> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Kelly Martin , 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 List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 24 Oct 2009 17:49:13 -0000 Paul Schmehl wrote: > --On Saturday, October 24, 2009 4:16 AM -0500 Matthew Seaman > 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 ..." 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 > $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`"? 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