Question: 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?
When running cron jobs on Linux, it’s common to receive output from the job in the form of email notifications or log files. However, in some cases, you may not want to receive output at all, especially if the job is running frequently or generates a lot of output. In this article, we’ll show you how to disable crontab output on Linux.
Method 1: Redirect output to /dev/null
The easiest way to disable crontab output is to redirect the output to /dev/null. Which is a special file that discards all data written to it. By redirecting output to /dev/null, you can effectively discard all output generated by the cron job.
To redirect output to /dev/null, add the following line to your crontab entry:
This will redirect both standard output and standard error to /dev/null, effectively disabling all output from the command.
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.
Method 2: Set the MAILTO environment variable
By default, cron sends email notifications for each job. However, you can disable email notifications by setting the MAILTO environment variable to an empty value.
To disable email notifications for a specific job, add the following line to your crontab entry:
This will set the MAILTO environment variable to an empty value, disabling email notifications for the current job.
Method 3: Modify the cron daemon configuration
If you want to disable crontab output for all jobs on your system, you can modify the cron daemon configuration. By default, the cron daemon sends email notifications for all jobs, but you can modify the configuration to disable email notifications.
To modify the configuration, edit the “/etc/crontab” file and add the following line:
This will set the default MAILTO value to an empty value, disabling email notifications for all jobs.
By using the methods outlined in this article, you can easily disable crontab output on Linux. Whether you choose to redirect output to /dev/null, set the MAILTO environment variable, or modify the cron daemon configuration, it’s important to test your changes thoroughly to ensure that your cron jobs are running correctly. With these techniques, you can have greater control over the output and notifications you receive from cron jobs on your Linux system.
doesnt work i keep seeing this in syslog every minute: “wget http://example.com/cron.php >/dev/null 2>&1″
Why is >/dev/null 2>&1 appended to the line after MAIL TO=”[email protected]” ?
Thanks! I had over 150.000 files in my home directory from a cronjob running wget every two minutes.
Thank you Mr. Rahul. It’s very helpful