1834935 Members
2187 Online
110071 Solutions
New Discussion

cron job executed time

 
j773303
Super Advisor

cron job executed time

Why the cron job executed time was early 5 hours show in /var/adm/cron/log? For ex: the cron job a.sh will execute at 13:00, but it is shows the execute time is 8:00 in /var/adm/cron/log? I also check the TZ = EAT-8. How to troubleshoot it?
Hero
8 REPLIES 8
Michael Tully
Honored Contributor

Re: cron job executed time

Check to make sure of the timezone being used for the command. You could always insert a timezone variable into the script/command that is being run. cron is not very intelligent when it comes to variables and path statements. They must be included in the scripts.

if [ -r /etc/TIMEZONE ]
then
. /etc/TIMEZONE
else
TZ= EAT-8
export TZ
fi

Anyone for a Mutiny ?
j773303
Super Advisor

Re: cron job executed time

I modify the a.sh
TZ = EAT-8
export TZ
echo $TZ > a.log
...

After the a.sh was run by cron, I view the
a.log shows the EEST? What's happend on it?
Why it is not show EAT-8?
Hero
Michael Tully
Honored Contributor

Re: cron job executed time

I created a similar test and just placed the TZ in a file as below and got the correct result. Check your script.

$ cat a.sh
TZ=EAT-8
export TZ
echo $TZ >a.log
$ sh a.sh
$ cat a.log
EAT-8
$
Anyone for a Mutiny ?
j773303
Super Advisor

Re: cron job executed time

Did you put the a.sh into cron job?
I also get the right result while run the
a.sh directly, but get the fault result while
a.sh was run in cron job.
Hero
Zigor Buruaga
Esteemed Contributor

Re: cron job executed time

Hi,

Try adding this
--------------------
TZ = EAT-8
export TZ
echo $TZ > a.log
date >> a.log
. /etc/TIMEZONE
date >> a.log
--------------------

and see what happens, I have tested it via cron and works OK:

EAT-8
Fri Aug 8 14:51:00 EAT 2003
Fri Aug 8 08:51:01 METDST 2003


Regards,
Zigor
j773303
Super Advisor

Re: cron job executed time

Below are the results,

TZ = EAT-8
export TZ
echo $TZ > a.log
date >> a.log
--------------------

The ouputs is:

EEST
Fri Aug 8 14:51:00 EAT 2003


Since the /var/adm/cron/log logs the date time
are belong EEST, which is not mine want. I would /var/adm/cron/log to show correct Timezone "EAT-8". But the result always shows the "EEST", how to fix it?
Hero
Zigor Buruaga
Esteemed Contributor

Re: cron job executed time

Hi,

I have just tested this via cron:
--------------------
TZ=EAT-8
export TZ
echo $TZ > a.log
date >> a.log
TZ=EEST
export TZ
echo $TZ >> a.log
date >> a.log
---------------------

and the log file contains:
---------------------
EAT-8
Fri Aug 8 15:14:01 EAT 2003
EEST
Fri Aug 8 07:14:01 EEST 2003
---------------------------
Difference of 8 hours.

What about your /etc/TIMEZONE?

Regards,
Zigor
j773303
Super Advisor

Re: cron job executed time

/etc/TIMEZONE
EAT-8

This is a strange issue. Does any has experience on this? While I was installed os is bundled on EEST, but I had been modify the /etc/TIMEZONE and TZ to EAT-8, why the cron job still known the ESST and logs error time to /var/adm/cron/log?
Hero