Linux:Change Crontab Email Settings

This post will guide you how to change the crontab email settings in your Linux operating system. How to change the default email recpient on your cron jobs under the Linux system.The crond service will sent an email to the default system root user, and if you want to send an mail to another specified mail account. How to achieve it. Or How do I set the sender address from mail sent from your cron jobs in Linux.

Change Crontab Email MAILTO Settings


The Cron daemon will check the cron jobs in /etc/crontab if the jobs should be run at the current date and time. When executing commands or scripts, and the outputs of commands or scripts will be mailed to the owner of the crontab. And if you set the MAILTO variable in the crontab file, and the output is mailed to the user that set by MAILTO variable.

So if you want to receive all email on test@osetc.com , you just need to replace root value with new email account.  Like this:

Before:

MAILTO=root

After:

MAILTO=test@osetc.com

Set the Sender Address For Crontab Email


If you want to specify the sender address for your cron email alert, you can set a MAILFROM variable in your crontab file, like this:

MAILFROM=sender@osetc.com

Then any ouput from your cron jobs will be sent to your MAILTO address, and all sender for those mails will be use your MAILFROM Address.

Using .Forware file to Receive All Email


If you want to sent all Crontab Email to a specified email account, you can try to create a new file named .forward under “/root”directory, and add email address into this file.

# echo all@ostec.com >/root/.forward

Stop Particular Cronjob Mails


If you do not receive mails for a particular cronjobs, and you can add this line at the end of that cron job: “>/dev/nul 2>&1”

Just like:

1 3  *  *  *  * /fio.sh >/dev/nul 2>&1

Then you will do not get any mail alert from this cron job.

Stop all Cronjob Mails


If you do not receive any mail alert for your cron jobs, you just need to remove the value of the MAILTO variable from the /etc/crontab file.

Just like this:

MAILTO=””

 

You might also like:

Sidebar



back to top