Simpler Navigation for Servers and Operating Systems
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
cancel
Showing results for 
Search instead for 
Did you mean: 

NO mail from crontab

Fouad_1
Occasional Contributor

NO mail from crontab

Allow me to introduce myself. Fouad from Mauritius

PLease confirm!
When you submit jobs in crontab you only receive mail if the job was unsuccessful. In case the job was successful you do not receive any mail.

This is my case. Is it normal?
Thanks in advance.
Intelligent people ask question, Others wait silently.
7 REPLIES
Dan Hetzel
Honored Contributor

Re: NO mail from crontab

Hi Fouad,

You'll receive mail after a crotab job has executed in the following cases:
1. Job was unsuccessful
2. Job is writing to standard output or standard error without being redirected either to a file or to /dev/null.

Thus, a job like 'echo hello' will have his output (hello) mailed, while a job like 'echo hello >/dev/null 2>&1' will not.

Best regards,

Dan
Everybody knows at least one thing worth sharing -- mailto:dan.hetzel@wildcroft.com
Dan Hetzel
Honored Contributor

Re: NO mail from crontab

Hi again,

Don't forget to redirect BOTH stdout and stderr, otherwise you could get mail.
It's always better to redirect to a file as this will leave you with a trace in case all went wrong.

Dan
Everybody knows at least one thing worth sharing -- mailto:dan.hetzel@wildcroft.com
Fouad_1
Occasional Contributor

Re: NO mail from crontab

Thanks (Dan) for the clarification. Now let me explain my problem.
I have a root crontab file. It contains commands (of course). The command is having some errors and some standard output. So it should mail the root user but in fact it does not. But I can find the output in /var/spool/cron/tmp. I have no redirection to that file in my crontab file.
I am running HP-UX 11.00 on an N-Class machine. Root do get other mails from other programs.
Why root is not being mailed in this special case?

Please help and thanks in advance.
Intelligent people ask question, Others wait silently.
Dan Hetzel
Honored Contributor

Re: NO mail from crontab

Hi Fouad,

Here is an abstract of the crontab manual page:

--QUOTE
WARNINGS
Be sure to redirect the standard output and standard error from
commands. If this is not done, any generated standard output or
standard error is mailed to the user.
--ENDQUOTE

You could try redirecting (stdout and stderr) to a file (as in 'command > /tmp/file 2>&1')

If the file isn't empty after job completion, its content is what should have been emailed without redirection.

Just in case, if you're running HP-UX 11.0, here is a link to the latest Cumulative cron/at/crontab patch

ftp://ftp.itrc.hp.com/hp-ux_patches/s700_800/11.X/PHCO_21494

Best regards,

Dan
Everybody knows at least one thing worth sharing -- mailto:dan.hetzel@wildcroft.com
Philip Chan_1
Respected Contributor

Re: NO mail from crontab

Fouad,

Your command program may have written to the /var/spool/cron/tmp directory explicitely, or it does re-directing standard output and standard error internally. What happens if you run the command under shell without cron? do you see any outputs?

~Philip
Carlos Fernandez Riera
Honored Contributor

Re: NO mail from crontab

insert in your command file:
set -x
exec >/tmp/trace1 2>&1

now you can see trace of your shell and analyze it.

then remove exec stament. Now all that must be redirected to mail. See also /var/mail dir.
unsupported
Fouad_1
Occasional Contributor

Re: NO mail from crontab

Hi all
Something strange happened. After having done the tests you guys told me. (Adding redirection and so) and returning the crontab file to its original contents, I began receiving mail from cron once again. I do not understand how the problem was solved. The administrators of the system asssured me they did nothing.
Nevertheless thanks for all your help and your precious time.

Regards

Fouad
Intelligent people ask question, Others wait silently.