Go Back   The macosxhints Forums > OS X Help Requests > UNIX - Newcomers



Reply
 
Thread Tools Rating: Thread Rating: 6 votes, 5.00 average. Display Modes
Old 05-25-2005, 01:27 PM   #1
jmooers
Prospect
 
Join Date: May 2005
Posts: 4
Question stop cron from sending mail

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.
jmooers is offline   Reply With Quote
Old 05-25-2005, 04:51 PM   #2
csdk0713
Prospect
 
Join Date: Dec 2004
Posts: 39
Add this to the end of your cron line:

Code:
>/dev/null 2>&1
So you'd have:

Code:
15 * * * *  runme.sh >/dev/null 2>&1
csdk0713 is offline   Reply With Quote
Old 05-25-2005, 06:21 PM   #3
nkuvu
MVP
 
Join Date: Jun 2002
Location: Tucson, Arizona
Posts: 1,236
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.

update: miscopied the thread address (left off an 8). thanks for the catch, cpragman

Last edited by nkuvu; 05-26-2005 at 09:24 AM.
nkuvu is offline   Reply With Quote
Old 05-26-2005, 05:28 AM   #4
cpragman
All Star
 
Join Date: Jan 2004
Location: Limerick, PA
Posts: 858
Actually, it's this thread.

Put the parameter on a line by itself in the crontab file (i.e., at the top of the file).

Code:
MAILTO=""
For example, here's a copy of my user's contab file now...
Code:
#
#
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.
cpragman is online now   Reply With Quote
Old 05-26-2005, 09:43 AM   #5
jmooers
Prospect
 
Join Date: May 2005
Posts: 4
re: stop cron from sending mail

Quote:
Originally Posted by nkuvu
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.

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.
jmooers is offline   Reply With Quote
Old 05-27-2005, 12:54 PM   #6
csdk0713
Prospect
 
Join Date: Dec 2004
Posts: 39
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.
csdk0713 is offline   Reply With Quote
Old 05-27-2005, 03:01 PM   #7
jmooers
Prospect
 
Join Date: May 2005
Posts: 4
Unhappy

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?
jmooers is offline   Reply With Quote
Old 05-27-2005, 03:38 PM   #8
nkuvu
MVP
 
Join Date: Jun 2002
Location: Tucson, Arizona
Posts: 1,236
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?
nkuvu is offline   Reply With Quote
Old 05-31-2005, 01:36 PM   #9
jmooers
Prospect
 
Join Date: May 2005
Posts: 4
Ok, so I have restarted the script, as described above. I am still getting emails. Here is a copy of my /etc/crontab file.

Quote:
# /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.
jmooers is offline   Reply With Quote
Old 05-31-2005, 03:09 PM   #10
cpragman
All Star
 
Join Date: Jan 2004
Location: Limerick, PA
Posts: 858
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.
cpragman is online now   Reply With Quote
Old 05-31-2005, 03:59 PM   #11
ajp
Triple-A Player
 
Join Date: Oct 2003
Location: Philadelphia, PA, USA
Posts: 80
i use this quick bash script to track down weird cron entries.

Code:
#!/bin/sh
for name in `nireport . /users name`; do
	echo -n "$name: "
	sudo crontab -u $name -l
done
ajp is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 05:41 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.