1851709 Members
5641 Online
104062 Solutions
New Discussion

cronjob

 
SOLVED
Go to solution
Deoncia Grayson_1
Honored Contributor

cronjob

This is my problem... I have job schedule to kick off on Mondays at 21:00 which generates reports and suppose to send a mail to users... The thing is the job works fine from the command line but if cron runs the job it generates the report but doesn't send the emails.. .any thoughts as to why this could be occuring?
If no one ever took risks, Michelangelo would have painted the Sistine floor. -Neil Simon
18 REPLIES 18
Steven E. Protter
Exalted Contributor

Re: cronjob

Cron has no environment file.

Any variable your script needs like:
PATH
TERM

has to be set explicitly in the cron script.

Sometimes you can include a user source file in the script

. /home/username/.profile

That might help.

That is the most common cause of this issue.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Geoff Wild
Honored Contributor

Re: cronjob

Another thing - you can log your cron jobs like so for example:

# logrotate
#
0 0 * * * /opt/logrotate/bin/logrotate /etc/logrotate.conf >/tmp/logrotate.cron 2>&1


Any errors will be in /tmp/logrotate.cron


Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Deoncia Grayson_1
Honored Contributor

Re: cronjob

The variables are set in the script. This is not a root cronjob but a users cronjob. I will log the errors to try to capture what is happening because the logs in /var/adm/cron are not telling me anything useful, just that the job ran.
If no one ever took risks, Michelangelo would have painted the Sistine floor. -Neil Simon
Geoff Wild
Honored Contributor

Re: cronjob

Okay - if the user's cron is executing a script, for more detail, add a

set -x

near the top of the script on its own line...(after #!/bin/sh or what have you)

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Mark Greene_1
Honored Contributor

Re: cronjob

What mail agent are you using and what's the system load like at the time? Sendmail will sometimes refuse connections if the system gets too busy.

You can check your mail queue with mailq -v -d to see if there are rejects or mail sitting in the queue going nowhere. You can force-flush the queue with sendmail -v -d8.20 -q

Also, if you are using aliases to send the e-mail, check the permissions on /etc/mail to see if other has read permissions.

mark
the future will be a lot like now, only later
Mark Greene_1
Honored Contributor

Re: cronjob

sorry, that's /etc/mail/aliases and /etc/aliases (which is a link to the former).

mark
the future will be a lot like now, only later
john korterman
Honored Contributor

Re: cronjob

Hi,
if the cron log states that the job ran and actually ended without errors, the problem i s more likely in the mail system or in that direction.
However, try and check the mail of the user in question; it might give a clue.

regards,
John K.
it would be nice if you always got a second chance
Deoncia Grayson_1
Honored Contributor

Re: cronjob

We're using elm to mail the files

elm -s "QC Aging - NLR" $MAIL_SEND_TO_NLR < qc_aging_nlr.txt


This works fine when manually ran, but not inside the cronjob.
If no one ever took risks, Michelangelo would have painted the Sistine floor. -Neil Simon
Geoff Wild
Honored Contributor

Re: cronjob

You can try with mailx:

mailx -s "QC Aging - NLR" $MAIL_SEND_TO_NLR < qc_aging_nlr.txt

But best to wait to see the /tmp/cronjob.log....

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Sundar_7
Honored Contributor

Re: cronjob

Hi Deoncia,

You dont have to wait till next Monday to look at the output from the script :-).

By default, cron sends stdout and stderr to the user's UNIX mailbox, if there is no output redirection.

Refer the /var/mail/. You should see the output from the script. Post the error message here. This can get you the answer for your problem.

- Sundar.
Learn What to do ,How to do and more importantly When to do ?
Geoff Wild
Honored Contributor

Re: cronjob

Sundar - that's true - unless the cron entry is like so:

0 22 * * 4 /usr/local/bin/fsadm.defrag >/dev/null 2>&1

In which case the errors are gone...

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Sundar_7
Honored Contributor

Re: cronjob

You are right Geoff. But I pressume Deoncia doesnt have it redirected.
Learn What to do ,How to do and more importantly When to do ?
Deoncia Grayson_1
Honored Contributor

Re: cronjob

From root Tue Oct 26 21:00:03 CDT 2004
Received: (from root@localhost) by maydist2.maybelline.com (8.8.6 (PHNE_17190)/8
.7.1) id VAA03707 for ohio; Tue, 26 Oct 2004 21:00:03 -0500 (CDT)
Date: Tue, 26 Oct 2004 21:00:03 -0500 (CDT)
From: root
Message-Id: <200410270200.VAA03707@maydist2.maybelline.com>
Subject: cron

/ohio/bin/qc_aging.sh[20]: qc_aging_nlr.txt: Cannot find or open the file.
logout

This error that cron is mailing to the user, but the file does exist.
ls -lai qc_aging_nlr.txt
169 -rwxrwxrwx 1 ohio users 151 Oct 25 11:01 qc_aging_nlr.tx
t
If no one ever took risks, Michelangelo would have painted the Sistine floor. -Neil Simon
Geoff Wild
Honored Contributor
Solution

Re: cronjob

Yes - but I think you need the absolute path in the script:

Instead of:

elm -s "QC Aging - NLR" $MAIL_SEND_TO_NLR < qc_aging_nlr.txt


try

elm -s "QC Aging - NLR" $MAIL_SEND_TO_NLR < /the/path/to/qc_aging_nlr.txt


Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Sundar_7
Honored Contributor

Re: cronjob

Geoff has it. Use full path to the filename and not just the relative path name.

Learn What to do ,How to do and more importantly When to do ?
john korterman
Honored Contributor

Re: cronjob

Hi,
regarding the error in line 20:
/ohio/bin/qc_aging.sh[20]: qc_aging_nlr.txt: Cannot find or open the file.

does the script look for the file in the correct directory?

regards,
John K.
it would be nice if you always got a second chance
Deoncia Grayson_1
Honored Contributor

Re: cronjob

Thanks everyone for your time and contributions. The issue is resolved. Big thanks to Geof and Sundar!
If no one ever took risks, Michelangelo would have painted the Sistine floor. -Neil Simon
Deoncia Grayson_1
Honored Contributor

Re: cronjob

see final remarks again Thanks everyone
If no one ever took risks, Michelangelo would have painted the Sistine floor. -Neil Simon