Solved

crontab and timezone

Posted on 1999-01-22
31
766 Views
Last Modified: 2008-03-03
unix box is in EST TZ (so is its default TZ)
i am in PST TZ
when i put XX in crontab, i want it to mean XX in PST, not EST
any ideas?
0
Comment
Question by:weinerk
  • 12
  • 11
  • 2
  • +5
31 Comments
 
LVL 84

Expert Comment

by:ozo
Comment Utility
put XX+3 in crontab
or change the default TZ of the unix box
0
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
call your command in crontab as follows:

   env TZ=PST your_command
0
 
LVL 1

Author Comment

by:weinerk
Comment Utility
1) xx+3 - no good - means to much work
2) change defalt TZ - not an option
3) env TZ=PST your_command - will not help - cron still will tribgger at the wrong time

i wrote a script  DelayByThreeHours
so in crontab - i have  DelayByThreeHours my command
it reads standard in and command line params an fires of an at-job at now+3hours



0
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
> cron still will tribgger at the wrong time
you mean that your entry is, let's say at 15:00 and you want it run at 18:00

This can only be done in one of following ways:
  1) set TZ as desired for your kernel, then reboot
  2) adjust you time in crontab (see ozo's comment)
  3) call a script which looks as follows:
     #! /bin/sh
       at now + 3 hours your_command

Probaly you may specify the at command in crontab itself (I have not tested it).
0
 
LVL 1

Expert Comment

by:elfi
Comment Utility
This may sound silly, but why not just set the cronjob to run three hours later than it's set for now?
0
 
LVL 1

Author Comment

by:weinerk
Comment Utility
ahoffmann,
i am doing something like 3
the tricky part was to take care of piping,redirection,etc



0
 
LVL 1

Author Comment

by:weinerk
Comment Utility
elfi,
crontab entry - needs to be meaningfull to a person who enters it
(in his timezone)

plus there is A LOT of them
shifting around becomes a nightmare if you consider the case of appointments bleeding over in the next day because of TZ change


0
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
so was my at suggestion a solution for your problem?
0
 
LVL 1

Author Comment

by:weinerk
Comment Utility
ahoffmann,

no that solution i had fully implemented before your suggestion
(read history)
i am looking for a better solution, since there are a few drawbacks in my kludge.


0
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
Ok, missed your 1'st comment.
Sorry, I'm out of ideas :-(

Aah stop, an ugly one:

sleep 10800; you_command
0
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
are you willing to use a small perl wrapper, which gets the command(s) to be executed as argument?
0
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
are you willing to use a small perl wrapper, which gets the command(s) to be executed as argument?
0
 
LVL 1

Author Comment

by:weinerk
Comment Utility
yes - that is what i am doing
and the perl script
reads stdin and args
and fires it off as at job at now + 3 hours
0
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
no; I mean I can post a script which you use directly via cron, like:

x x x x x wrapper "your_command and some args | other command > logfile"

(probably the destination TZ as additional argument)
where the  wrapper is a perl script which calculates the difference of timezones itself
and delays the command (given as argument).
Technically it will do a simple sleep, but you don't need to take care about calculating timezone differences.
Again, it's just a more sophisticated way, somehow, than just doing an at (or a sleep as in my last comment).
0
 
LVL 1

Author Comment

by:weinerk
Comment Utility
i have a better script
it does all that
x x x x x wrapper "your_command and some args | other command > logfile"

but not through sleep,
it resets an "at now + N hours"-command


0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
I agree, at is to be prefered over sleep.
So if you have a script, what need you else?
0
 
LVL 1

Author Comment

by:weinerk
Comment Utility
it is still an ugly KLUDGE
(it only works for westward timezones,
cant easily cancel the task if it already fired of
etc...etc...etc...etc...)

i am hoping for a better solution :(

0
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
as I said: a perl wrapper which is independent of source and target TZ (of cause, one of them must be hardcoded, or passed via argument), delaying the command using at
Is this better, for you?
0
 
LVL 1

Author Comment

by:weinerk
Comment Utility
forget it
it does not solve any of the problems
eastward TZs problem is that is the default TZ is PST
and the user is in EST - then by the time crontab fires it off - you have to go back in time!
etc...etc...etc...etc...
just forget it - a KLUDGE is a KLUDGE
0
 
LVL 2

Expert Comment

by:blowfish
Comment Utility
Since you asked for ideas, I'll post mine as an answer.  I would prefer to code and test it myself, but won't have the time to do it over the next few days.  I think that you'll find this one is rather original.  

Write a perl wrapper that queries and saves in a variable the system's TZ and the user's TZ.  Then perform the following:

1.  Dump the contents of the user's crontab into a temp file, using a system call to crontab -l.  
2.  Then perform a substitution on each non-comment line, to convert the hour field to the user's local TZ by applying the appropriate offset.  
3.  Optionally, insert a comment at the beginning of the file to indicate that the system TZ is XX, all entries have been converted to the user's TZ of XX.  
4.  Next, invoke the user's $EDITOR, to allow them to make their modifications.  
5.  Once the file is saved, perform a substitution, to convert the hour field from the user's TZ back to the system TZ, using the appropriate offset.  
6.  If you chose to add the comment above, you should delete it, or modify it prior to re-loading the data into crontab.  
7.  Now, reload the data via another system call to crontab.  

This type of solution is sometimes refered to as writing a "front-end".  If you can get it to work, and you're really bold, you may even try calling it "crontab" and installing it in your user's PATH ahead of the system crontab binary.  

Hope this helps,
--frankf
0
 
LVL 2

Expert Comment

by:blowfish
Comment Utility
Would you care to provide some commentary explaining the reason for your rejection?  

Thanks,
--frankf
0
 
LVL 1

Author Comment

by:weinerk
Comment Utility
blowfish,

yes.
what you have described in a great detail is THE PROBLEM,
i am looking for a SOLUTION.
i know that i could hire a secretary to take care of all those conversions, but that is hardly a technical answer to my problem.
sorry

0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
Do you want a program to take care of all those conversions?
0
 
LVL 1

Author Comment

by:weinerk
Comment Utility
writing a whole new front end to crontab is going to be nasty

because so far we have only disscussed converting input.
it will also require converting output back when you do  
crontab -l

and though it is POSSIBLE (grouping things by special comments etc) it is sertainly nasty

i by no means mean to challenge anybody on whether it is doable
i just hope all realize whats involved
0
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
combining all the ideas about a wrapper, front-end, etc., let's call this suggestion a  (crontab) converter:

   perl program reading the user's crontab and converting all its entries to the appropriate TZ

The user can be extrcted from the environment, while the TZ comes as parameter.
The program can replace the original crontab by the new one and notify crontd.
0
 
LVL 1

Author Comment

by:weinerk
Comment Utility
ahoffmann,

dont forget the second half - a way to convert all back in case user decided to add a couple of jobs for example

0
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
.. this is the simple task:

   alias crontab 'crontab \!*; conv_crontab'

or something similar
Of cause, it could not start jobs in the past ;-)
0
 

Expert Comment

by:donner
Comment Utility
Cron has been unable to deal with this issue at least since 1985 when I tripped over it.
You've hit on one of the real deficiencies of cron ... it should support multiple time zones
and run in GMT.

One idea that I never tried was to run several *different* cron processes, each with a
different timezone and a *different* crontab file.  I don't know if you can do this.  The
SunOS cron documentation doesn't indicate that you can specify an alternate crontab
directory.

A last trick is to have a set of crontabs, one per time zone and a Perl script that
parses each of them at cron start time and does the right transformation of the crontab
to the local time zone and then catenates them all together to build the 'real' crontab
in local time.
0
 
LVL 1

Author Comment

by:weinerk
Comment Utility
i dont have root permissions
0
 
LVL 5

Expert Comment

by:tfabian
Comment Utility
what difference does it make if the jobs run at 13:00 est, or 13:00 pst??  I understnad there could be greater load at time, but if the main point is getting the job to run, why is time so important??
0
 
LVL 2

Accepted Solution

by:
bedot earned 100 total points
Comment Utility
cron is launched under the login root: so i think it takes always the TZ of root;
a solution should be that the crontab execute an su XX -c at .... where the user XX has your own TZ (forse your login);
note that "at jobs" take the whole environment of the user;
the only problem is that is necessary to execute at command before (and not too late);
BUT is very important to take care of your TZ? you can't add yourself the amount of hours necessaries?

0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

772 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now