Why the time will change to another Timezone?

Hello~

I write a script using 'here document' syntax, for example:

#!/bin/ksh

mailx -s "This is a test mail" davis@flora.com<<EOF

`date`

That's it!!

EOF

And, I put it into cron job, when I got the email, I found the date time is slower 8 hours from the system time!! That is,

the system time is 'Tue May 29 11:14:44 CST 2007',

but the mail I got will be 'Tue May 29 03:14:44 EST 2007'!!

However, I run the script from command line, I got the correct time as system time. I am very confused at that, can anyone help?

Thanks!!

I>

[623 byte] By [davistai@gmail.coma] at [2007-11-27 5:44:13]
# 1
Hmm, presumably the TZ environment variable is different in the cronjob.Not sure why that would be.What do you get from grep TZ /etc/default/initYou could explicitly set TZ in the shell script.
robert.cohena at 2007-7-12 15:24:41 > top of Java-index,General,Sys Admin Best Practices...
# 2
Check 'grep TZ /etc/default/init' is the same as system environment, however, if run from cron job, the date will show +8 hr than system time!!But, if you run from command line, the date will be the same as system time..how strange it is,isn't it?
davistai@gmail.coma at 2007-7-12 15:24:41 > top of Java-index,General,Sys Admin Best Practices...
# 3
are u sure the timezone set correctly? check out the user profile for the cron user.# date ; date -u; echo $TZTue May 29 01:24:10 CDT 2007Tue May 29 06:24:10 GMT 2007US/Centraltest ur script with su -c# su - user_name -c "sh script"
chaossisxya at 2007-7-12 15:24:41 > top of Java-index,General,Sys Admin Best Practices...
# 4
you could refer this as well. http://forum.java.sun.com/thread.jspa?threadID=5164632
chaossisxya at 2007-7-12 15:24:41 > top of Java-index,General,Sys Admin Best Practices...
# 5

Hello,Guys,

I just reboot the system, and test the cron job again..You guess what?

The date time is correct from the email this time!!

I tried to recall what I've done to the system, then, I remembered that before the problem occurred, I just killed a wrong process, yes, it is 'cron' process, however, I start it by using '/etc/init.d/cron start' right after I found the mistake, and the problem was found when the cron job invoke at the assigned time..

I don't know if there's any relatiponship between them, just wondering the 'cron' process can't be start up by using /etc/init.d/cron manually?

davistai@gmail.coma at 2007-7-12 15:24:41 > top of Java-index,General,Sys Admin Best Practices...