• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2568
  • Last Modified:

How to change the timezone in Centos Unix for Crontab

Hi,
I have taken a VPS on Centos UNIX and need to schedule a job in it. The server was in MST timezone and I changed the timezone to IST and scheduled my cronjobs according to IST. However, it seems that my crontab is referencing time from a different timezone and still seems to be using MST. When I type the "date" command at the command line I see the time as IST. In the cronjob I'm running a Java program and not a script.
Please let me know if I need to make a change in the php.ini or do I need to check something else so that crontab refers to IST.


Thanks.
0
orazen12
Asked:
orazen12
  • 6
  • 5
1 Solution
 
woolmilkporcCommented:
You will have to restart the cron daemon to make it recognize the new timezone setting!

/sbin/service cron restart

or look here for details:
http://www.linuxmail.info/how-to-start-stop-services-centos-5/

wmp
0
 
orazen12Author Commented:
Thanks woolmilkporc.

Once I restart the daemon, is there a way I can check what timezone my crontab is taking. I'd just like to verify that it is taking the correct timezone.
0
 
woolmilkporcCommented:
Easiest way - schedula a cron job:

* * * * * echo $TZ > /tmp/TZ

and check the output in /tmp/TZ

Don't forget to remove the job when you're done!

wmp
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
orazen12Author Commented:
woolmilkporc,

When I did

echo $TZ

at the command line it's showing me a blank line. Does that mean there's some problem with the way I've changed the timezone?
0
 
woolmilkporcCommented:
Seems so. How did you change it?
0
 
woolmilkporcCommented:
Did you update /etc/localtime?

If so, what do you get with "date" ?

If "date" shows the correct timezone only the TZ variable is not set, which might not be mandatory on CentOS.

Change your test cronjob to

* * * * * date > /tmp/date

And check /tmp/date.

wmp
0
 
orazen12Author Commented:
Ok it is working fine now. Yeah the TZ variable was not set and date is returning the right result. Actually I didn't know the cron daemon needs to be restarted. date was always showing the correct result.

Thanks for your help.
0
 
woolmilkporcCommented:
Additionally examine /var/log/cron for correct timestamps.
0
 
orazen12Author Commented:
The typo in the solution is that it should be crond for centos. Just mentioning here so that anyone else reading it will get the complete command.

/sbin/service crond restart
0
 
woolmilkporcCommented:
Thanks for the points and particularly for the correction! You're right, of course!

Cheers

wmp
0
 
orazen12Author Commented:
Got it. Thanks.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now