View Full Version : stop cron from sending mail
jmooers
05-25-2005, 01:27 PM
Hi all,
I am new to cron, but have (with the help of the mailman list) figured out a way to create a cron event. The problem is that I am now getting an email everytime the script runs. I have no interest in receiving this message every 15 minutes of the day.
Running OS 10.3.9 Server on a colo Xserve. Any help would be greatly appreciated.
csdk0713
05-25-2005, 04:51 PM
Add this to the end of your cron line:
>/dev/null 2>&1
So you'd have:
15 * * * * runme.sh >/dev/null 2>&1
nkuvu
05-25-2005, 06:21 PM
That will redirect the output of whatever command to /dev/null, but cron will still email status messages. What you need to do is set MAILTO to null. The syntax (in your crontab file) is:
MAILTO=""
Note that this was covered in another recent thread (http://forums.macosxhints.com/showthread.php?t=39888).
update: miscopied the thread address (left off an 8). thanks for the catch, cpragman
cpragman
05-26-2005, 05:28 AM
Actually, it's this thread (http://forums.macosxhints.com/showthread.php?t=39888).
Put the parameter on a line by itself in the crontab file (i.e., at the top of the file).
MAILTO=""
For example, here's a copy of my user's contab file now...
#
#
MAILTO=""
#
30 * * * * /Users/Shared/Staff/Applications/sharenice.csh
@reboot cd /Users/cpragman/Applications/FAH5; ./fah5 -local -advmethods -forceasm -verbosity 9 &
#SqzS VERSION = 1.0.0
#SYMANTEC SCHEDULER CRON ENTRIES. THESE ENTRIES ARE AUTOMATICALLY GENERATED
#PLEASE DO NOT EDIT.
# Enc=1 Name="FileSaver Daily Update" EvType1=3 EvType2=0 Sched=3
0 12 * * * "/Library/Application Support/Norton Solutions Support/Scheduler/schedLauncher" 0 "/Library/Application Support/Norton Solutions Support/Norton Utilities/Norton Volume Assist" " " "oapp" "aevt" "exAG" "-d0"
# Enc=1 Name="Daily Defragmentation" EvType1=4 EvType2=0 Sched=3
0 0 * * * "/Library/Application Support/Norton Solutions Support/Scheduler/schedLauncher" 0 "/Library/Application Support/Norton Solutions Support/Norton Utilities/Norton Defragger" " " "oapp" "aevt" "exAG" "-d0"
# Enc=1 Name="Update Virus Protection" EvType1=1 EvType2=0 Sched=1
0 18 1 * * "/Library/Application Support/Norton Solutions Support/Scheduler/schedLauncher" -u 0 "/Applications/Norton Solutions/LiveUpdate.app/Contents/MacOS/LiveUpdate" " " "oapp" "aevt" "exAG" "-update LUdf"
#SqzS END SYMANTEC CRON ENTRIES
It works. Just note that you won't get any mail from cron for the user in question.
jmooers
05-26-2005, 09:43 AM
That will redirect the output of whatever command to /dev/null, but cron will still email status messages. What you need to do is set MAILTO to null. The syntax (in your crontab file) is:
MAILTO=""
Note that this was covered in another recent thread (http://forums.macosxhints.com/showthread.php?t=39888).
update: miscopied the thread address (left off an 8). thanks for the catch, cpragman
Thanks for the replies. I did the above, will see if it works. Sorry about reposting after the issue had already been addressed in a previous thread. I did search the archives, but did not see it.
csdk0713
05-27-2005, 12:54 PM
The MAILTO thing is great if you never want to receive email from cron, but when debugging an automated process, sometimes you want to receive mail from one or more (but maybe not all) cron jobs. That's why I usually do it line by line as listed above. It's all about having options.
jmooers
05-27-2005, 03:01 PM
Well I tried it but it did not work.
I added
MAILTO=""
to my /etc/crontab file. It is for user mailman, who as far as I can tell does not have its own crontab file. Any other suggestions?
nkuvu
05-27-2005, 03:38 PM
After you add the MAILTO to the cron file, you have to tell crontab to update it:
crontab filename
It doesn't happen automagically. Did you do this?
jmooers
05-31-2005, 01:36 PM
Ok, so I have restarted the script, as described above. I am still getting emails. Here is a copy of my /etc/crontab file.
# /etc/crontab
SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin
HOME=/var/log
MAILTO=""
#
#minute hour mday month wday who command
#
#*/5 * * * * root /usr/libexec/atrun
#
# Run daily/weekly/monthly jobs.
15 3 * * * root periodic daily
30 4 * * 6 root periodic weekly
30 5 1 * * root periodic monthly
Now that I look at the above code, I don't see the script, thought it is clearly running. The user is mailman. Is there another file that I should be looking for? I am running this through webmin. I do know how to use the terminal and pico into a file as well.
Thanks for your patience.
cpragman
05-31-2005, 03:09 PM
If you modified /etc/crontab, then you changed ROOT's behavior, so you shouldn't get any more e-mails from the various root maintenance tasks that run.
If you have users with cron scripts, they are edited a different way. Check out man crontab. You can't really edit a user's cron file directly. The closest you can come is "crontab -e username", which will open a vi editor session of the username in question's crontab file. (You might need "sudo crontab -e username" for a user other than yourself).
If your system has an imaginary user names mailman that is generating the e-mails, then you need to "sudo crontab -e mailman", and add the MAILTO="" line to that users crontab file.
i use this quick bash script to track down weird cron entries.
#!/bin/sh
for name in `nireport . /users name`; do
echo -n "$name: "
sudo crontab -u $name -l
done
vBulletin® v3.8.7, Copyright ©2000-2014, vBulletin Solutions, Inc.