Operating System - Linux
1747988 Members
5068 Online
108756 Solutions
New Discussion юеВ

Re: mail after run crontab job

 
SOLVED
Go to solution
haeman
Frequent Advisor

mail after run crontab job

I found that when the system run crontab job , it will send a mail to system , for example , if the crontab job is run by root , then a mail will be sent to root@my_domain , can advise if I want to stop to send the mail , what can i do ? thx
5 REPLIES 5
Ivan Ferreira
Honored Contributor
Solution

Re: mail after run crontab job

You have two options.

Redirect STDOUT and STDERR to somewhere in your job, for example:

0 1 * * * /path/to/job.sh > /dev/null 2>&1

Or set at the begining of your cron definitions:

MAILTO=""
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Rasheed Tamton
Honored Contributor

Re: mail after run crontab job

>root@my_domain

You have to remove the root@my_domain part from the cron line or from the script as above.

Otherwise, please post the exact lines from the script/cron.

Rgds.
haeman
Frequent Advisor

Re: mail after run crontab job

thx replies,

Ivan's method is good , but I have many many line , if use this method , the cron file will become very large ,


Hi Rasheed Tamton ,

where is the line that contains the root@my_domain ?
Rasheed Tamton
Honored Contributor

Re: mail after run crontab job

>I found that when the system run crontab job , it will send a mail to system , for example , if the crontab job is run by root , then a mail will be sent to root@my_domain , can advise if I want to stop to send the mail , what can i do ? thx

It is from your original post.

Rgds.
Ciro  Iriarte
Valued Contributor

Re: mail after run crontab job

As Ivan stated above, put 'MAILTO=""' on the first line of the crontab, that work for 1 or 36565 entries...

--------
MAILTO=""
* * * /bin/test.sh
* * * /bin/blah.sh
etc
etc
--------