1827741 Members
3168 Online
109969 Solutions
New Discussion

Re: Cron and timezone

 
SOLVED
Go to solution
Tim Rotunda
Frequent Advisor

Cron and timezone

Is there any possible method of forcing cron to inherit the $TZ of the user that submitted it?
Thanks for any help.
TR.a
11 REPLIES 11
someone_4
Honored Contributor

Re: Cron and timezone

Hi there,
First I am wondering what your objective is? If I am not mistaken the timezone would or should be the time zone where the server sits.What is your end goal?

Richard
Tim Rotunda
Frequent Advisor

Re: Cron and timezone

I have a server at EST and user environments at PST, CST and EST. Each environment has a crontab that schedules things according to the local environment and I need these things to get scheduled according to the local environment time not local server time. Did that make sense?
TR.a
someone_4
Honored Contributor

Re: Cron and timezone

what happends when you do

echo $TZ
for each user? Does the time zone come up for each user? I am assuming you are setting the $TZ in the .profile in the home dir right?

Richard
Tim Rotunda
Frequent Advisor

Re: Cron and timezone

Yes, the TZ is set in each .profile. I understand that cron does not inherit TZ from the user, but I am looking for a way to force it.
someone_4
Honored Contributor

Re: Cron and timezone

Hi Tim,
If I am not mistaken you have your server in EST and users every where else. And you want the user in CST to run his cron jobs at this time. And EST to run his at this time and so on. Well I have been looking and looking and cant find anything about this.

I did find this in the man pages for crontab:

cron invokes the command from the user's HOME directory with the POSIX
shell, (/usr/bin/sh). It runs in the c queue (see queuedefs(4)).

cron supplies a default environment for every shell, defining:
HOME=user's-home-directory
LOGNAME=user's-login-id
PATH=/usr/bin:/usr/sbin:.
SHELL=/usr/bin/sh

Users who desire to have their .profile executed must explicitly do so in the crontab entry or in a script called by the entry.


So here is my 2nd idea. Mr. Clay has a great script called the cal.sh script it is a very famous and I would even go as far as saying legendry for fixing every date and time delema that comes though the forum. So give it a try and let us know what happends. If anything I will bring this post back to the top and see what the day crew has to say. I have become very intrested if cron can do this or not.

example of script working with a cron job with version 2.03

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x1b397b8d1de3d5118ff40090279cd0f9,00.html


new version here 2.05

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xea948cc5e03fd6118fff0090279cd0f9,00.html

Richard
someone_4
Honored Contributor

Re: Cron and timezone

Ok Tim I found two docs that would helped. I attached them but have not had a chance to test them out. Let me know if it works.

Richard
Deepak Extross
Honored Contributor

Re: Cron and timezone

Richard,
I'm not convinced sourcing the .profile in the of crontab will help.

This is because is invoked only *after* the cron daemon decides that it's time to run the job. At the time of deciding, crond will continue to use the Server TZ.

But yes, if itself uses $TZ, then sourcing the .profile will allow it to use the User's value of $TZ, rather than that of the server.
Trond Haugen
Honored Contributor
Solution

Re: Cron and timezone

In my view cron is run "by the system" which is in EST. cron is kind of just another process and has inherited the TZ when started. What you want is another cron (3 actually) running in PST, CST and EST., which would have been fine if they hadn't read the same crontab...
I do understand (I think) that you want the users to operate in their own time zone but I don't think you can have them run cron jobs in any other than the system TZ. Will it help them to run at-jobs? As they are scheduled from the shell they will be in the users TZ.

Regards,
Tron
Regards,
Trond Haugen
LinkedIn
Deepak Extross
Honored Contributor

Re: Cron and timezone

While Clay's caljd.sh is indeed the Holy Grail of all date-related issues, I think it will be overkill in this situation.
All that the users need to do is calculate the difference between their local $TZ and the Server's, and adjust the time (HH and MM) accoringly in their crontab files.
Tim Rotunda
Frequent Advisor

Re: Cron and timezone

The "root" of the issue is as Tron pointed out, cron runs and schedules jobs in its own time. The solution here is to make cron sensitive to the users TZ needs or able to run in multiple environments. at may be the solution here and seems viable. Thanks very much!
TR.a
someone_4
Honored Contributor

Re: Cron and timezone

Tim,
It looks like this is not the first time this has been brought up. Here is a case dated back to 1998 but as you see "This defect is under investigation".I wonder if anything has come of this yet?


######################
######################

ER: add timezone field to crontab syntax

Current Path Home
Score : 0
Document Type : SR
Date : 1998 Oct 27
Description : ER: add timezone field to crontab syntax
Document Id : 5003440131
Search String :

You may provide feedback on this document

View the printer friendly version of this document



--------------------------------------------------------------------------------

Problem Text

CR# JAGaa52110
problem
Cu would like an enhancement to CRON to be able to handle jobs running
for different timezones on a single machine.

Essentially cu would like to be able to place a timezone entry in the
crontab file so the times will automatically adjust for a particular
timezone

eg. User in Queensland wants to run a job at say 8:00 Queensland time.
The unix machine is located in NSW which is currently in daylight
savings and is hence 1 hour behind QLD.
When the user in Queensland submits the cron job for 8:00 the job will
be run at 8:00 NSW time and hence will be run an hour late.

Sysadmin wants to be able to put a Timezone entry in the crontab file
for Queensland that will cause the cron job to be run at an adjusted
time.

Fix Text

fix
This defect is under investigation