Operating System - HP-UX
1832991 Members
2592 Online
110048 Solutions
New Discussion

Re: Cannot send mail in crontab

 
Margarida Brito
Frequent Advisor

Cannot send mail in crontab

Hi,

In command line I send mail do internet addresses but when i put the same command in crontab it doesn’t work.

Can anybody tell me why?

It is HP-UX 11.23

the content of the script testemailx is:

su - username -c "/usr/bin/rm /tmp/obj_create.out; sqlplus '/as sysdba' @ /cron_scripts/obj_create.sql;"
/usr/bin/mailx -s "TestMailx " name@somewhere.com < /tmp/obj_create.out


the line in crontab:
* * * * * /tmp/testemailx > /tmp/testemailx.out 2>/tmp/testemailx.err
7 REPLIES 7
Dave La Mar
Honored Contributor

Re: Cannot send mail in crontab

Well, the simple answer is that not all environmental variables are set when running through cron.
Try adding any obvious envirnmental variables to the script as well as full paths to any command you are using.

Regards,

-dl
"I'm not dumb. I just have a command of thoroughly useless information."
Dennis Handly
Acclaimed Contributor

Re: Cannot send mail in crontab

Anything in /tmp/testemailx.err?
You seem to have absolute paths for everything except sqlplus.

Do you have read permission on /tmp/obj_create.out, created by a different user?
Margarida Brito
Frequent Advisor

Re: Cannot send mail in crontab

environmental variables:
I make in the script env > /tmp/testeMailxEnv and the result is the same as my user env, except for the following variables:
MANPATH, COLUMNS, EDITOR, HISTFILE, ERASE, PS1, TERM, LINES
I don't think this will be important...

for the output of /tmp/testemailx.err is
ttytype: couldn't open /dev/tty for reading
stty: : Not a typewriter
Not a terminal
stty: : Not a typewriter
stty: : Not a typewriter

Yes I have permissions for /tmp/obj_create.out

I also tried with sendmail comand in the script but the result was the same, no mail was send.


Dennis Handly
Acclaimed Contributor

Re: Cannot send mail in crontab

MANPATH, COLUMNS, EDITOR, HISTFILE, ERASE, PS1, TERM, LINES
>I don't think this will be important...

It doesn't seem like it.

>for the output of /tmp/testemailx.err is
ttytype: couldn't open /dev/tty for reading
stty: : Not a typewriter

You need to clean up your .profile and /etc/profile to not execute stty and ttytype if you are not interactive. You can guard it by either:
if [ "${-%%*i*}" != "$-" ]; then
if tty -s; then

>I also tried with sendmail comand in the script

If you can echo something after sendmail, then it would show the issue with the mail system and not cron.
Margarida Brito
Frequent Advisor

Re: Cannot send mail in crontab

the output from sendmail is one:

username@somewhere.com... Connecting to proxymail.domain.com via relay...
220 proxyserver.domain.com Microsoft ESMTP MAIL Service, Version: 6.0.3790.1830 ready at Wed, 19 Sep 2007 11:58:53 +0100
>>> EHLO server.domain.com
250-proxyserver.domain.com Hello [110.111.134.140]
250-AUTH GSSAPI NTLM
250-TURN
250-SIZE 15728640
250-ETRN
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-8bitmime
250-BINARYMIME
250-CHUNKING
250-VRFY
250 OK
>>> MAIL From: SIZE=16 AUTH=root@+81w.domain.com
250 2.1.0 root@server.domain.com....Sender OK
>>> RCPT To:
250 2.1.5 username@somewhere.com
>>> DATA
354 Start mail input; end with .
>>> .
250 2.6.0 <200709191100.l8JB00a11727@server.domain.com> Queued mail for delivery
username@somewhere.com... Sent ( <200709191100.l8JB00a11727@server.domain.com> Queued mail for delivery)
Closing connection to proxymail.domain.com
>>> QUIT
221 2.0.0 proxyserver.domain.com Service closing transmission channel
Margarida Brito
Frequent Advisor

Re: Cannot send mail in crontab

ok it is now working.
The output of sendemail helped.

I edit the /etc/mail/sendmail.cf

where is was
# class E: names that should be exposed as from this host, even if we masquerade
CE root
I change to
CE

where it was
# class L: names that should be delivered locally, even if DH is set
CL root
I change to
CL

Thanks for the input.
Margarida Brito
Frequent Advisor

Re: Cannot send mail in crontab

The solution is in the above message