Stop the php5 cron emails

March 2, 2016 4.3k views
System Tools Ubuntu

Hi, I have installed SSMTP - and everything works, but now I'm getting some Cron emails that I wasn't expecting.

I've tried a number of things to try to disable them, but nothing seems to be working.

Delivered: root@windfarmstudios.com → postmaster@windfarmstudios.com 'Cron <root@windfarm> [ -x /usr/lib/php5/maxlifetime ] && [ -x /usr/lib/php5/sessionclean ] && [ -d /var/lib/php5 ] && /usr/lib/php5/sessionclean /var/lib/php5 $(/usr/lib/php5/maxlifetime) > /dev/null 2>&1'

I've tried adding mailto="" before the cron command.
I've also tried appending > /dev/null 2>&1 as you can see above.

Anyone have some suggestions?

1 Answer

Chaining the commands this way should result in a single exit which would have it's output redirected to /dev/null preventing the email but without seeing the exact line in the crontab it's hard to tell for sure.

The mailto option to stop all cron related emails can be done like this.

Open /etc/crontab in an editor

You should see these lines:

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

Directly after those, append:

MAILTO=""

Then save the file and run

service cron restart

and the change should take effect.

  • Hi @ryanpq - sorry for the late response ... unfortunately your suggestions didn't work. So here's all the files:

    /etc/crontab

    # /etc/crontab: system-wide crontab
    # Unlike any other crontab you don't have to run the `crontab'
    # command to install the new version when you edit this file
    # and files in /etc/cron.d. These files also have username fields,
    # that none of the other crontabs do.
    
    SHELL=/bin/sh
    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    MAILTO=""
    
    # m h dom mon dow user  command
    17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
    25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
    47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
    52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
    #
    

    /etc/cron.d/php5

    # /etc/cron.d/php5: crontab fragment for php5
    #  This purges session files older than X, where X is defined in seconds
    #  as the largest value of session.gc_maxlifetime from all your php.ini
    #  files, or 24 minutes if not defined.  See /usr/lib/php5/maxlifetime
    
    # stop the email!!
    mailto=""
    
    # Look for and purge old sessions every 30 minutes
    09,39 * * * *  root  [ -x /usr/lib/php5/maxlifetime ] && [ -x /usr/lib/php5/sessionclean ] && [ -d /var/lib/php5 ] && /usr/lib/php5/sessionclean /var/lib/php5 $(/usr/lib/php5/maxlifetime) > /dev/null 2>&1
    

    Any other info you need, or suggestions?

Have another answer? Share your knowledge.