SERVERS · 8 JAN 2021 · 2 MIN READ

Getting rid of the email the cron manager sends us

Sometimes we have to set up a cron task on our hosting, generally in cPanel, but once it is configured and verified we don't want it to keep sending us an email with the result of each run.

Sometimes it has happened to us that we need to set up a cron task on our hosting, generally in cPanel, but once it is configured and verified we don’t want it to keep continuously sending us an email with the result of that execution.A very typical case where we don’t want to receive these emails is, for example, in Moodle, where we must run an internal system cron task every minute, or at most every 5 or 10 minutes, so the number of emails that arrive daily overwhelms us and becomes unmanageable.

With this simple trick, you will be the one who controls whether or not you receive the email from the cron task manager, or you can even make it come at certain times and not at others. In any case, it lets us get rid of that email which is often a headache and you’re not quite sure what to do with.

How to remove the email

In this case the solution is very simple: all we have to do is add “>/dev/null 2>&1” after our command, which tells it to discard the result and do nothing with it. This way the system will have no output at all, all output is discarded, and the system will have nothing to send us by email. So our cron task will look, for example, like this:

/usr/local/bin/php /home/miusuariodecpanel/public_html/cron-a-ejecutar.php >/dev/null 2>&1

 

How to receive the email again

If we want to receive the email again to debug the cron that runs, you just have to remove what we added earlier and you will go back to receiving the email from your cPanel. The instruction would then look like this:

/usr/local/bin/php /home/miusuariodecpanel/public_html/cron-a-ejecutar.php

 

Is this happening on a project in production?

We audit and fix WordPress and Laravel installations every week.

Let’s talk
Scroll to Top