Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have the following line in my /etc/cron.d/apache2watch file

* * * * * root /bin/apache2-restart.sh &> /dev/null

I am currently receiving hundreds of mails to root because of this. I don't know why root is still receiving mail every second or so telling me that the cron job was run - even though I have clearly redirected outputs to /dev/null

Can anyone explain why root continues to receive mail, and how I can change this behaviour?

I am running on Ubuntu 10.04 LTS

share|improve this question
add comment

4 Answers

You are still receiving emails probably because you have only redirected standard output to /dev/null. Your shell script probably writes to stderr too, so correct redirection would be like:

* * * * * root /bin/apache2-restart.sh > /dev/null 2>&1
share|improve this answer
add comment

Insert MAILTO="" before you crontab line.

share|improve this answer
add comment

You have redirected outputs to /dev/null, but only if you're using bash as your crontab shell. I believe that by default you'd be using /bin/sh.

To fix it, I'd recommend thor's solution:

* * * * * root /bin/apache2-restart.sh > /dev/null 2>&1

The other solution is to change CRON to use bash by putting this at the beginning of your crontab entry:

SHELL=/bin/bash
share|improve this answer
add comment

why don't you set MAILTO="" in particular user's here 'root' crontab. This will disable logging of mail messages in /var/spool/mail/

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.