From: "Carlos E. R."
Date: Fri, 14 Oct 2005 02:42:21 +0200 (CEST) To: SLE Subject: Re: [SLE] crontab +email -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
The Thursday 2005-10-13 at 16:09 -0700, Art Fore wrote:
I want to run cat/proc/mdstat as root as a cron job once a day and have it email the results to my work email account. Checked crontab -e, etc, but am still very confused. The MAILTO= seems to be only for a user.
If I do a crontab -e
MAILTO= "mylogon@comcast.net" 5 0 * * * cat /proc/mdstat
You'd better create a script that does exactly what you want, and set that script to be run from cron. The mailto setting affects every job defined, and by default (in suse settings) only sends something on errors.
As I think about it, Carlos is right. I'd do something like this: #!/bin/bash # Define a tempfile - date +%s outputs seconds since 00:00:00 01-01-1970 # and so ensures uniqueness TEMPFILE="/tmp/mdstat.`date +%s`" # Put mdstat output into a tempfile cat /proc/mdstat >> ${TEMPFILE} # cat the tempfile, and pipe it to mail (actually, nail) # -r "some@somewhere.com" defines the sender address # -s "some subject" defines the subject line # and the destination address goes after the subject cat ${TEMPFILE} | mail -r "fromaddress@someserver.com" -s "mdstat output: `date +%D`" "toaddress@someserver.com" # Get rid of the tempfile rm ${TEMPFILE} # Exit cleanly exit 0 ########################## Done here And, if you want to be really smart about it -- you'll set this to be executable and put it into the directory /etc/cron.daily/ -- then it'll be run each day at (I believe) 4 AM. (Just put the script into that directory -- no need for a crontab line).