From owner-freebsd-questions@FreeBSD.ORG Sun Jul 15 15:57:58 2007 Return-Path: X-Original-To: questions@freebsd.org Delivered-To: freebsd-questions@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 8015A16A401 for ; Sun, 15 Jul 2007 15:57:58 +0000 (UTC) (envelope-from derek@computinginnovations.com) Received: from betty.computinginnovations.com (mail.computinginnovations.com [64.81.227.250]) by mx1.freebsd.org (Postfix) with ESMTP id 2BBDC13C4B3 for ; Sun, 15 Jul 2007 15:57:57 +0000 (UTC) (envelope-from derek@computinginnovations.com) Received: from p28.computinginnovations.com (dhcp-10-20-30-100.computinginnovations.com [10.20.30.100]) (authenticated bits=0) by betty.computinginnovations.com (8.13.8/8.12.11) with ESMTP id l6FFsDTX004071; Sun, 15 Jul 2007 10:54:28 -0500 (CDT) Message-Id: <6.0.0.22.2.20070715104657.0248c960@mail.computinginnovations.com> X-Sender: derek@mail.computinginnovations.com X-Mailer: QUALCOMM Windows Eudora Version 6.0.0.22 Date: Sun, 15 Jul 2007 10:53:45 -0500 To: Mikhail Teterin From: Derek Ragona In-Reply-To: <200707141802.46034@aldan> References: <200707141603.55899@aldan> <6.0.0.22.2.20070714155424.0242a958@mail.computinginnovations.com> <200707141802.46034@aldan> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: questions@freebsd.org Subject: Re: Can cron e-mail HTML? 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: Sun, 15 Jul 2007 15:57:58 -0000 At 05:02 PM 7/14/2007, Mikhail Teterin wrote: >Derek Ragona wrote: >= = I'd rather avoid poluting my script with e-mail sending code... > >= You need to change your script to send the email itself. > >Thank you, Derek, but -- as I stated already -- I wanted to see, if this can >be avoided... Doing so makes it very non-portable. This would make your cron changes needed on any system and version you want to implement this behavior. >Since you posted your script, I'll comment on it. First of all, you don't >need >ksh for anything you are doing in this script. FreeBSD's /bin/sh is enough >(we aren't Solaris :-) -- but is 9 times smaller here (amd64). I don't need ksh for the particular sample I gave you, which is pared down from any I use. I posted a simple boilerplate that anyone who reads the list can use. For most things /bin/sh works well, but the overhead of ksh on a modern server is negligible. >Now, instead of redirecting each line of output into MAILFILE, then mailing, >and removing it, you should be either outputing everything directly into >mail: > > { > cat $REPORT_LOG_HEADER > echo " " >> $MAILFILE > echo " " >> $MAILFILE > echo "

" >> $MAILFILE > > .... > cat $REPORT_LOG_FOOTER > } | $MAIL -s "the report name" $MAILTO This was done as an example. In many cases I have reports generated in html, and simple email the URL of the report. >or, if you want to use the temporary file, use exec to redirect into it >_once_, instead of _on every line_: > > exec > $MAILFILE > cat $REPORT_LOG_HEADER > > printf " \n \n

\n" > $MAIL -s "the report name" $MAILTO < $MAILFILE > $RM $MAILFILE > >This may look nicer, but is not, because temporary files are nasty, and you >need to be sure, that you remove them in case you are interrupted (trapping >signals, etc.) I removed the signal handling from my example as I didn't want to add that much complexity. It is trivial to add proper signal handling. >I was surprised, one can not redirect into a pipe directly. The following did >not work, as I expected, with neither /bin/sh nor /usr/local/bin/ksh93. The >following, I thought, would be the same as my first example, only >nicer-looking: > > exec | $MAIL -s "the report name" $MAILTO > cat ..... > >But it is not. So you have to chose from one of the first two examples. This is UNIX. Meaning there are many ways to accomplish tasks. Just choose the tools and methods you want. I strive to make cron scripts simple and portable. I support a multitude of servers running different UNIX versions and flavors. -Derek