Operating System - HP-UX
1748255 Members
4120 Online
108760 Solutions
New Discussion юеВ

Re: Script Execution Unable to Log When Executed Via Cron

 
SOLVED
Go to solution
sysad_boy
Frequent Advisor

Script Execution Unable to Log When Executed Via Cron

I have a number of scripts that when executed manually logs everything on how it executes step by step. Problem is when these scripts are ran via cron logging is not complete.

Did some minor troubleshooting:
1. Checked the user that executes the job if he is a member of the cron.allow file.
2. Checked Directory Permissions
3. Changed the default shell of the user from /usr/bin/sh to /sbin/sh
4. Placed an ampersand "&" at the end of the script in crontab (e.g.: * * * * * /dir/script.sh &)

But to no avail. What seems to be the problem with cron?


TIA
21 REPLIES 21
sujit kumar singh
Honored Contributor
Solution

Re: Script Execution Unable to Log When Executed Via Cron

hi

can you please sahre the O/ps of the job as run maunally as well as the error that you get while executing the job as with cron.


the cron logs you can find at /var/adm/cron/log file.

please share as well the O/p of the command

crontab -e as run as root

regards
sysad_boy
Frequent Advisor

Re: Script Execution Unable to Log When Executed Via Cron

Actually there is no error being encountered.

I placed several lines inside my scripts to echo everything that it does to a file. There are actually two parts of the script logging. 1st part it logs the date, time of execution. 2nd part it logs several select commands to the DB.


The log looks like this when executed manually:


===> START Tue Jan 12 04:30:00 EAT 2010

Date From:
Date To:
Processing DM ACR
Interactive mode off.

(1 row affected)
Create table tempdb..XXX_ACR
(0 rows affected)
Extract ACR for Stream 0
(643 rows affected)
Consolidate data for Stream 0

===> END Tue Jan 12 15:09:52 EAT 2010


However when executed via cron, it only outputs:

===> START Tue Jan 12 15:14:00 EAT 2010

Date From:
Date To:
Processing DM ACR
Interactive mode off.
===> END Tue Jan 12 15:14:01 EAT 2010



I dont know why this is happening when the scripts is executed via cron.
sujit kumar singh
Honored Contributor

Re: Script Execution Unable to Log When Executed Via Cron

Hi

what are your crontab entries for the same job , can you please tell.



try redirecting the O/P as well as errors to some file and check.

also you can check actual result that this should perform sa run as a cron job for the same.


regards
sujit
Horia Chirculescu
Honored Contributor

Re: Script Execution Unable to Log When Executed Via Cron

Seems that your script does not find some file/utility. Maybe you should try to set in the script the PATH variable, like in:

PATH=/usr/sbin:/usr/bin:/whatever....

(You can copy this variable from the one that your system is using - see profile for root)

Best regards,
Horia.

Best regards from Romania,
Horia.
sysad_boy
Frequent Advisor

Re: Script Execution Unable to Log When Executed Via Cron

PATH is already defined in the user's .profile do I also need to place it inside my script?
john korterman
Honored Contributor

Re: Script Execution Unable to Log When Executed Via Cron

Hi,

>>PATH is already defined in the user's .profile ..<<

Please notice that no login is performed when a cron job is executed, hence the user's .profile is not read.
You should define your variables or the full command paths in your script.

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

Re: Script Execution Unable to Log When Executed Via Cron

As John Korterman pointed, you must declare this in your script (in order to avoid strange behavoir of your script).

Horia.
Best regards from Romania,
Horia.
sysad_boy
Frequent Advisor

Re: Script Execution Unable to Log When Executed Via Cron

Ok, i just did your advice but to no avail. Same result.
Horia Chirculescu
Honored Contributor

Re: Script Execution Unable to Log When Executed Via Cron

What exactly does your script? Can you post it here?

Horia.
Best regards from Romania,
Horia.