Solved

How to change the timezone in Centos Unix for Crontab

Posted on 2011-03-07
11
2,210 Views
Last Modified: 2012-05-11
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
Comment
Question by:orazen12
  • 6
  • 5
11 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 35055246
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
 

Author Comment

by:orazen12
ID: 35055322
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
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 35055504
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:orazen12
ID: 35055738
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
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 35055756
Seems so. How did you change it?
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 35055855
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
 

Author Comment

by:orazen12
ID: 35055908
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
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 35055915
Additionally examine /var/log/cron for correct timestamps.
0
 

Author Closing Comment

by:orazen12
ID: 35055927
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
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 35055947
Thanks for the points and particularly for the correction! You're right, of course!

Cheers

wmp
0
 

Author Comment

by:orazen12
ID: 35055956
Got it. Thanks.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Move nodes from one TSM to another. 3 95
retrieve nuemaric value from txt file in shell script 3 82
Sed question 2 124
problem creating new luks volume on new VM disk 5 117
Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question