1837257 Members
2398 Online
110115 Solutions
New Discussion

Re: cron / mail

 
HelderAfonso
New Member

cron / mail

how can i disable the cron to send mail after the execution task?

Thanks!!!
6 REPLIES 6
Dennis Handly
Acclaimed Contributor

Re: cron / mail

You make sure that stdout and stderr are redirected, to /dev/null if you want.
Jollyjet
Valued Contributor

Re: cron / mail

can you brief the question

if you want the cron entry to disable you can add a commit # in front of the line.
Jaime Bolanos Rojas.
Honored Contributor

Re: cron / mail

Hello!

To disable cron from mailing output to root add the following to the end of the
cron entry:

> /dev/null (this redirects std. out to the bit bucket)

2> /dev/null (this redirects std. error to the bit bucket)

> /dev/null 2>&1 (this redirects both std. out and std. error)

Here are a couple of examples:

0 1 * * * /path/command [options] > /dev/null


0 1 * * * /path/command [options] > /dev/null 2>&1

Regards,

Jaime.
Work hard when the need comes out.
john korterman
Honored Contributor

Re: cron / mail

Hi,

mail resulting from cron execution indicates that the job has produced output that could not be redirected to e.g. a file.
Therefore, if you take care of redirecting all output to a file (or more files), there will be no reason for sending any mail.

Example without redirection, which may produce mail:
00 9-15 * * 1-5 su sysadm -c /usr/local/bin/mail_top.sh >/tmp/mail_top.sh.yt

Example with redirection:
00 9-15 * * 1-5 su sysadm -c /usr/local/bin/mail_top.sh >/tmp/mail_top.sh.yt 2>&1

In the example with redirection you should pay attention to the fact that the shell evaluates redirection from left to right:
First, std. out is associated with the file /tmp/mail_top.sh.yt
Secondly, std. err ("2") is associated with whatever std. out ("1") is associated with. As std. out was already associated with the file /tmp/mail_top.sh.yt then std. err will go to the same file.

The example only show redirection from the two "normal" output channels, std. out and std. err. Technically, a job could produce output to other data channels, but let us for a start assume that this not the case!


regards,
John K.
it would be nice if you always got a second chance
HelderAfonso
New Member

Re: cron / mail

resolved
Dennis Handly
Acclaimed Contributor

Re: cron / mail

You neglected to assign any points to your answers. See:
http://forums1.itrc.hp.com/service/forums/helptips.do?#33

Here is how to reopen a thread:
http://forums1.itrc.hp.com/service/forums/helptips.do?#41

>John: a job could produce output to other data channels,

cron only cares about stdout and stderr.