How can I disable email alerts from cron jobs? How can I disable wget to create a new file each time? Why I am receiving too many e-mails to my root account from crontab?. This tutorial will help you to disable crontab output and email notifications.
I have run multiple crontabs on my Linux system for regular tasks like backups, data processing, etc. Each time the cron job run sends a new email to me. Also, there are some wget commands configured in crontab which is creating a huge number of files under the home directory.
Suppress Cronjob Output and Logs
You can easily suppress the output of any cronjob by redirecting output to /dev/null. You can do this by appending
>/dev/null 2>&1 to cronjob, for which you want to suppress output.
0 2 * * * /home/backup.sh >/dev/null 2>&1
- The >/dev/null tells the cron to send all output (STDOUT) to /dev/null
- The 2>@1 tells the cron to send all errors (STDERR) to same as (STDOUT)
This is more useful for the cron jobs running wget command. I have a cron job with wget run every minute. Which creates a new file each time wget runs with crontab under the home directory. So I configured it as below and now my home is clean.
0 2 * * * wget -q -O /dev/null http://example.com/cron.php
Using MAILTO Option
You can disable the email notification for cronjob by setting MAILTO=””. You can also set the same variable to some other email to send an email specified from the specific job.
MAILTO="" 0 2 * * * /home/backup.sh >/dev/null 2>&1 MAILTO="[email protected]" 0 2 * * * /home/backup.sh >/dev/null 2>&1
Thank you for reading this tutorial. You may also like our tutorial Crontab in Linux with 20 useful examples for scheduling cron jobs.