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


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

Insert MAILTO="" before you crontab line.

  • it might be worth mentioning that even with this, the output will be retained in a temporary file until the process exits without sending a mail; this may even fill up the filesystem where /tmp is. – törzsmókus Feb 6 '19 at 13:06

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

  • Some cronjobs were saved in /var/spool/mail/, I would never found this without you, thank you! – Luca Steeb Jul 14 '15 at 12:44

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:

  • this answer is correct – but you might have simply edited thor’s incorrect answer instead – törzsmókus Feb 6 '19 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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