Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have CentOS and when I run date command in shell it return me something like:

Thu Apr 28 14:08:20 GMT 2011

however cron jobs are running at PST time.Means if I specify

15 7 * * * command

it will run at 7 PST not 7 GMT . Please tell me why this is happening.

Thanks

Outputs of hwclock command:

/usr/sbin/hwclock --utc Cannot access the Hardware Clock via any known method.
Use the --debug option to see the details of our search for an access method.

And when I ran using debug:
/usr/sbin/hwclock --debug hwclock from util-linux-2.13-pre7 hwclock: Open of /dev/rtc failed, errno=2: No such file or directory. No usable clock interface found. Cannot access the Hardware Clock via any known method

share|improve this question

3 Answers 3

More than likely not your problem, but worth a mention -- If your /etc/localtime changes after crond has loaded, it will continue to be stuck in the previous timezone. Simply restart/reload crond, and it will pick up this change.

Another 'gotcha' is that cron will adhere to the TZ environment variable. This can be set in-line in a crontab, affecting any lines that follow it, but it seems more likely that TZ is getting set in the environment that loads crond.

I just tried a couple variations (tweaking the hr/min fields) on the following to determine if/when these two jobs would be run. The output that gets stuffed into /tmp/tzout.localtime should also give you some hints about if $TZ is somehow getting set in the environment that's loading crond or not.

* * * * *     echo $TZ `date` >> /tmp/tzout.localtime
TZ=GMT
* * * * *     echo $TZ `date` >> /tmp/tzout.gmt

While I don't claim to know exactly where your problem lies, hopefully this sheds a little light on the solution!

share|improve this answer
    
Good idea to also check if there is a TZ variable set for the user, as opposed to cron. I would also recommend running the set command as a cron test. It might show something interesting being set in another variable. –  chutz Oct 29 '12 at 12:29
    
Thanks for the tip on reloading crond! –  Steven Jan 26 '13 at 0:06

I believe that "cron" runs based on the hardware clock, not the configured time-zone's clock. Try looking at "hwclock" rather than "date" as "date" is modified to your users' configured time-zone.

share|improve this answer
    
I got few errors while running hwclock: /usr/sbin/hwclock --utc Cannot access the Hardware Clock via any known method. Use the --debug option to see the details of our search for an access method. and when I ran using debug: /usr/sbin/hwclock --debug hwclock from util-linux-2.13-pre7 hwclock: Open of /dev/rtc failed, errno=2: No such file or directory. No usable clock interface found. Cannot access the Hardware Clock via any known method –  Shashwat Apr 28 '11 at 14:31
    
it's very strange that you would be seeing errors with hwclock... but any chance you can look @ bios-level for the time? is it set to the correct time for PST? –  TheCompWiz Apr 29 '11 at 13:01
    
-1, because all CentOS cron implementations that I am aware of (vixie-cron on CentOS 5, and cronie on CentOS 6) run based on the system clock, so this statement is just not true. –  chutz Oct 29 '12 at 12:27

The question is a bit old but changing the time zone and getting crond to recognize the change is still a problem on CentOS: I have found that after changing the time zone the syslog deamon also has to be restarted using

/etc/init.d/rsyslog

See Timzone incorrect for log files only?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.