By default all cron tab emails are sent to root user in Linux, But if you want send those emails to particular user this can be done by two methods.
A cron tab file contains instructions to the cron daemon, It gets active every minute to check all stored crontabs to see if it should be run in the current minute. When executing commands, any output is mailed to the owner of the crontab.
Default crontab configuration file settings.
Now open crontab configuration file using your favorite editor.
nano /etc/crontab
Change Crontab email alert id using MAILTO option.
Now I want to receive all email alerts on cppl@cpanelplesk.com. Then we just replace root id with new id in “/etc/crontab”
SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=cppl@cpanelplesk.com HOME=/ # For details see man 4 crontabs # Example of job definition: # .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri$ # | | | | | # * * * * * user-name command to be executed
Change Crontab email alert id using “.forward” file.
If we want to receive all the emails to cppl@cpanelplesk.com , we can do it by just creating a new file called .forward under “/root” and add the cppl@cpanelplesk.com email id.
nano .forward
How to stop particular cronjob mails.
If you run the cron every 5 mins and you will be getting email alert frequently and you want to stop/ban that cronjob mails. just add this line at end of the cronjob “>/dev/null 2>&1”.
0 4 * * * /usr/local/cpanel/bin/backup 0 3 * * * /usr/local/cpanel/scripts/cpbackup 12 2 * * 0 /usr/local/cpanel/bin/cloudflare_update.sh >/dev/null 2>&1
We haven’t get any mail alert of last cronjob.
How to stop/ban all cronjob mails.
If MAILTO is defined empty (MAILTO=””), no mail will be sent.
SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO= "" HOME=/ # For details see man 4 crontabs # Example of job definition: # .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue ,wed,thu,fri$ # | | | | | # * * * * * user-name command to be executed
Done!!
Go through this link to get more details about Cronjobs.