Solaris 9 Zone : Date command in crontab shows delayed(One Hour) output

SOLARIS 9 Zone :

date command in crontab shows delayed(One Hour) output

Hi folks,
the date command shows the correct date and time, How ever, if the date command executed through crontab in any form of scrip the output shows as one hour delayed, similar to date -u..

Can some one help in this..
++++++++++++++++++++++++++++++++++++++++++

Date command perfectly shows

judi:root:/tmp# date
Fri Feb 15 15:08:03 MET 2013
judi:root:/tmp#

The script used to get the output to test.out

judi:root:/tmp# more test.sh
#!/usr/bin/ksh
DT=`date '+%y%m%d-%H:%M'`
LOG=/tmp/test.out
echo $DT >> $LOG
judi:root:/tmp#

the cron entry used..

          • /tmp/test.sh

output of the script execution (delayed for one hour)
judi:root:/tmp# more test.out
130215-14:03
130215-14:04
130215-14:05
130215-14:06
130215-14:07
130215-14:08
judi:root:/tmp#

judi:root:/tmp# date
Fri Feb 15 15:08:10 MET 2013
judi:root:/tmp#

Setting the expected timezone in the script called from cron should workaround the issue, eg:

#!/bin/ksh
export TZ=Europe/Paris
DT=`date '+%y%m%d-%H:%M'`
LOG=/tmp/test.out
echo $DT >> $LOG

Alternatively, set/fix TZ in /etc/default/init and reboot the zone.

1 Like

Thanks for your reply jlliagre
the time zone is properly set and even server had a reboot after the time zone settings..

Did you modify the test.sh script as I suggested ?

yes I modified the test.sh, Now the output is perfect, still I am afraid this cannot be advised to all users and application cronjobs right ?

The clock is correct, the timezone setting is not for some reason. Please provide more clues/evidences.

Sorry , I dont have any clue and totally confused.. Please be more specific on what else we can check..
Also I did not find any thing interesting (about time settings) in /etc/.profile.. :frowning:

I guess that the TZ is set on a per user basis but not systemwide. As cron has a very limited environment, it may not have TZ set correctly. You can set TZ in the crontab files.

The TZ is set properly in /etc/TIMEZONE, how do I check the TZ is set on per user basics,
The issue is faced by all users who running the date command through cron

Put a TZ assignment into either crontab (man crontab) or /etc/profile (or whatever file will be used by the shell cron is running as the default ).

1 Like

Jlliagre and RudiC Thanks for your responces

In general, if I see the env command, all the servers are displaying the TZ=<timezone>, but this entry (TZ=<timezone>) is missing in this particular server, that too for all the users.. Hence I added the time zone settings in /etc/profile.. Now the cronjobs are giving the correct data and time (without any delay..)

My curiosity is from where this TZ=<timezone> variable is getting exported for servers, and why this server is not getting updated even the /etc/TIMEZONE file has proper entry..

Is /etc/TIMEZONE a symlink to /etc/default/init ?

yes that's correct... its a symlink ..