From owner-freebsd-questions@FreeBSD.ORG Sun Jul 15 08:07:11 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 C186516A400 for ; Sun, 15 Jul 2007 08:07:10 +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 085F413C4A5 for ; Sun, 15 Jul 2007 08:07:07 +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 l6ELCq0f093743; Sat, 14 Jul 2007 16:12:58 -0500 (CDT) Message-Id: <6.0.0.22.2.20070714155424.0242a958@mail.computinginnovations.com> X-Sender: derek@mail.computinginnovations.com X-Mailer: QUALCOMM Windows Eudora Version 6.0.0.22 Date: Sat, 14 Jul 2007 16:12:29 -0500 To: Mikhail Teterin , questions@freebsd.org From: Derek Ragona In-Reply-To: <200707141603.55899@aldan> References: <200707141603.55899@aldan> Mime-Version: 1.0 X-ComputingInnovations-MailScanner-Information: Please contact the ISP for more information X-ComputingInnovations-MailScanner: Found to be clean X-ComputingInnovations-MailScanner-From: derek@computinginnovations.com X-Spam-Status: No Content-Type: text/plain; charset="us-ascii"; format=flowed X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: 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 08:07:11 -0000 At 03:03 PM 7/14/2007, Mikhail Teterin wrote: >Hello! > >I have a script launched from cron every morning, that gets certain data over >the Internet from a remote computer, compares the new data with that from the >previous day, and outputs the difference (if any). > >I'm relying on the fact, that cron e-mails me the output of each job. > >However, I modified the script recently to produce the output (if any) in >HTML, rather than in plain-text format. > >The HTML arrives by e-mail just as well as plain text used to, but no e-mail >program will render it as such, because neither the cron(8), nor the mail(1), >which cron uses to send e-mail, creates MIME messages... > >How can I force the ``Content-Type: text/html'' header without hacking cron's >sources? I'd rather avoid poluting my script with e-mail sending code... > >Maybe, cron should apply file(1)-like logic to the e-mailed content? > >Thanks for any hints. Yours, You need to change your script to send the email itself. I have many scripts that email reports, legs, and html reports. To accomplish this I have my cron job run a script like this (I have simplified the script you should be able to use it as a base): #!/usr/local/bin/ksh # set full paths for all commands needed, and files needed MAIL=/usr/bin/mail MAILFILE=/tmp/mail_file #fill in your correct email or alias you wish to use MAILTO=me@mydomain.com RM=/bin/rm DATE=/bin/date AWK=/usr/bin/awk LS=/bin/ls GREP=/usr/bin/grep FIND=/usr/bin/find TODAY=`$DATE +%m-%d-%Y` REPORT_LOG_HEADER=/usr/local/etc/report_log_header REPORT_LOG_FOOTER=/usr/local/etc/report_log_footer # start the mailfile with the proper header, # in this case it is an HTML header cat $REPORT_LOG_HEADER > $MAILFILE #put more stuff into the report . . . echo " " >> $MAILFILE echo " " >> $MAILFILE # Add any processing or log files to the middle of the mail file here # you can even put HTML codes in here echo "

" >> $MAILFILE echo " " >> $MAILFILE # add the correct HTML footer cat $REPORT_LOG_FOOTER >> $MAILFILE # send it to yourself $MAIL -s "the report name" $MAILTO < $MAILFILE $RM $MAILFILE -Derek -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. MailScanner thanks transtec Computers for their support.