Re: Crontab for different ime zones
On Sat, 2009-05-23 at 23:41 -0600, Tim Judd wrote: SNIP I propose the following: cron itself has no concept of timezone. it is 'date' that is picking up TZ and reporting as such. Cron's job is so simple is that it wakes up each minute to see if it has work to do, regardless of timezone, or anything else. Yep - I understood that, Tim. Thew issue seems to be that cron pays no attention to TZ declarations that happen AFTER it wakes up - cron does not parse the job times using the new TZ. The thing I am struggling with is that 'date' picks up the changes imposed by 'TZ=', but then 'cron' parses the next line as if the job times are interpreted using the server's default TZ. I've tried using 'CRON_TZ=' as well as, and instead of, 'TZ=' - to no avail. What I thought ought to happen is this: * 'cron' wakes up; * 'cron' works through the crontab line by line; * at line 1 cron changes the TZ to America/NY; * at line 2 cron reads the job time in the context of having just been told that it's operating in the NY timezone (thus 45 13 * * * is 1:45 pm NY time); . . . * at line 15 cron is told to change the TZ to Australia/Sydney; * from line 14 onwards, 45 13 * * * is 1:45 pm SYDNEY time. . . . and so on. It seems that cron behaves as if it forgets $TZ at each newline within a given cron instance. The silly thing is, with all the time I've wasted pursuing this wild goose I could have built the required four crontabs, and written the script to swap them in and out on the appropriate dates. (Or I could have spent $100 and bought a shared-hosted server space to do the Australian-TZ stuff and given it sufficent permission to store the resultant data in y primary mySQL db...) Still, I think it's worth persevering with. I'm certain it can be done. You might want to try some other determining factor, such as a shell builtin. Good luck. Cheers ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: Crontab for different ime zones
On Sun, May 24, 2009 at 5:31 PM, GT catch@marketmentat.com wrote: On Sat, 2009-05-23 at 23:41 -0600, Tim Judd wrote: SNIP I propose the following: cron itself has no concept of timezone. it is 'date' that is picking up TZ and reporting as such. Cron's job is so simple is that it wakes up each minute to see if it has work to do, regardless of timezone, or anything else. Yep - I understood that, Tim. Thew issue seems to be that cron pays no attention to TZ declarations that happen AFTER it wakes up - cron does not parse the job times using the new TZ. The thing I am struggling with is that 'date' picks up the changes imposed by 'TZ=', but then 'cron' parses the next line as if the job times are interpreted using the server's default TZ. I've tried using 'CRON_TZ=' as well as, and instead of, 'TZ=' - to no avail. What I thought ought to happen is this: * 'cron' wakes up; * 'cron' works through the crontab line by line; * at line 1 cron changes the TZ to America/NY; * at line 2 cron reads the job time in the context of having just been told that it's operating in the NY timezone (thus 45 13 * * * is 1:45 pm NY time); . . . * at line 15 cron is told to change the TZ to Australia/Sydney; * from line 14 onwards, 45 13 * * * is 1:45 pm SYDNEY time. . . . and so on. It seems that cron behaves as if it forgets $TZ at each newline within a given cron instance. The silly thing is, with all the time I've wasted pursuing this wild goose I could have built the required four crontabs, and written the script to swap them in and out on the appropriate dates. (Or I could have spent $100 and bought a shared-hosted server space to do the Australian-TZ stuff and given it sufficent permission to store the resultant data in y primary mySQL db...) Still, I think it's worth persevering with. I'm certain it can be done. You might want to try some other determining factor, such as a shell builtin. Good luck. Cheers How about a jail for America/NY, and a jail for AU/Sydney? that might work. --TJ ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: Crontab for different ime zones
On Sun, 2009-05-24 at 18:45 -0600, Tim Judd wrote: How about a jail for America/NY, and a jail for AU/Sydney? that might work. --TJ That's a good solution, but I am still somewhat puzzled by cron's behaviour relative to what I expected from the man page. From the man page for crontab(8): In order to provide finer control over when jobs execute, users can also set the environment variables CRON_TZ and CRON_WITHIN. The CRON_TZ variable can be set to an alternate time zone in order to affect when the job is run. Note that this only affects the scheduling of the job, not the time zone that the job perceives when it is run. If CRON_TZ is defined but empty (CRON_TZ=), jobs are scheduled with respect to the local time zone. Problem is, CRON_TZ just doesn't work as written above. If you insert CRON_TZ=America/New_York and then write the * * * * * (schedule) to reflect NY time (say), but your server time is Chicago, cron ignores the CRON_TZ definition. Here's a CRONTAB extract which provides a good example of the odd behaviour: # - sample crontab # change tz and cron_tz to America/NY TZ=America/New_York CRON_TZ=America/New_York # check that timezone change 'stuck' (commented out except for testing) * * * * * printf CRON_TZ is now $CRON_TZ. Now doing US\n /home/targetdir/public_html/tmp/log.txt 21 * * * * * date /home/targetdir/public_html/tmp/log.txt 21 # Now, change both TZs to Australia/Sydney TZ=Australia/Sydney CRON_TZ=Australia/Sydney # check that timezone change 'stuck' (commented out except for testing) * * * * * printf CRON_TZ is now $CRON_TZ. Now doing Australia\n /home/targetdir/public_html/tmp/log.txt 21 * * * * * date /home/targetdir/public_html/tmp/log.txt 21 # - end sample crontab The result of that will be Mon May 25 11:02:01 EST 2009 CRON_TZ is now Australia/Sydney. Now doing Australia Sun May 24 21:02:01 EDT 2009 CRON_TZ is now America/New_York. Now doing US 'date' is right, and $CRON_TZ changes as expected, but has no effect in cron. One other thing strikes me as odd: the output file is in reverse order to the crontab. If changes to CRON_TZ actually worked as written, then one would need to verify that the changes propagated 'downstream' from the variable declaration. It's not that output is being written to the top of the outfile though - output in subsequent minutes is APPENDED to the outfile. And now for the big DUH, I'm an idiot moment - apparently FreeBSD, Fedora and Ubuntu don't have CRON_TZ support built in. It's gotten to the stage where you have to be wary of what you find in external man pages... Cheers GT ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Crontab for different ime zones
Late entry to this thread, but... I thought I had found an answer to this; at present I think I might have been mistaken. My crontab has about a dozen jobs that need to run in TZ=America/New_York, and another dozen that ideally want TZ=Australia/Sydney... the server default is America/Chicago. Given that the DST wobble for Australia/Sydney is not the same as for America/New_York (and given that I am lazy) I wanted ONE crontab that would serve year-round, rather than FOUR crontabs that had to be swapped in and out all the time (even if that could be done by a cron job). I thought I had found a solution - simply insert a line TZ=America/New_York before the US jobs, and TZ=Australia/Sydney before the Australian ones. A final statement to return TZ to sever default would be optional. I checked that TZ changes worked, by adding a cron job (for testing purposes) under each TZ declaration, of the form TZ=America/New_York * * * * * date /home/mysite/public_html/tmp/log.txt 21 and TZ=Australia/Sydney * * * * * date /home/mysite/public_html/tmp/log.txt 21 Sure enough, every minute, cron would dutifully change TZ to NY and change again to Sydney. There would be two datestamps in log.txt - one would show current US/NY time, one would show current Australia/Sydney time. Oddly they would appear in REVERSE order in the output file (Sydney first, then NY). PROBLEM: If I run a very simple PHP script after each TZ declaration - for example, one that writes date(Y-m-d H:i e) to the same log file - the PHP script returns the server default timestamp (US/Chicago). So the script does not 'see' the TZ (that is not a problem since my work scripts don't have any internal time dependencies - the only time dependency is the START time). Also, if I time the script as if cron is actually 'seeing' Sydney time, the scripts don't execute as expected. Example: it is currently 1:45 pm Sydney time. If I change TZ=Australia/Sydney * * * * * date /home/mysite/public_html/tmp/log.txt 21 to TZ=Australia/Sydney * 13 * * * date /home/mysite/public_html/tmp/log.txt 21 cron will NOT run the script... I bet it will wait until 13:00 CHICAGO time. I have a feeling that I am missing something relatively simple - at which point my dream of a super-cron will be realised and the stupidity of DST can be ignored (as it ought to be... ). I also bet that someone else has worked this out already, somewhere in the internets tubes... but i have been unable to find it. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: Crontab for different ime zones
2009/5/24 GT catch@marketmentat.com: Late entry to this thread, but... I thought I had found an answer to this; at present I think I might have been mistaken. My crontab has about a dozen jobs that need to run in TZ=America/New_York, and another dozen that ideally want TZ=Australia/Sydney... the server default is America/Chicago. [snip] TZ=Australia/Sydney * 13 * * * date /home/mysite/public_html/tmp/log.txt 21 cron will NOT run the script... I bet it will wait until 13:00 CHICAGO time. I have a feeling that I am missing something relatively simple - at which point my dream of a super-cron will be realised and the stupidity of DST can be ignored (as it ought to be... ). I also bet that someone else has worked this out already, somewhere in the internets tubes... but i have been unable to find it. I don't think the regular cron works like that. Check out ports/sysutils/fcron (man 5 fcrontab .. OPTIONS .. timezone ..). -- (nil) ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: Crontab for different ime zones
On Sat, May 23, 2009 at 9:46 PM, GT catch@marketmentat.com wrote: Late entry to this thread, but... I thought I had found an answer to this; at present I think I might have been mistaken. My crontab has about a dozen jobs that need to run in TZ=America/New_York, and another dozen that ideally want TZ=Australia/Sydney... the server default is America/Chicago. Given that the DST wobble for Australia/Sydney is not the same as for America/New_York (and given that I am lazy) I wanted ONE crontab that would serve year-round, rather than FOUR crontabs that had to be swapped in and out all the time (even if that could be done by a cron job). I thought I had found a solution - simply insert a line TZ=America/New_York before the US jobs, and TZ=Australia/Sydney before the Australian ones. A final statement to return TZ to sever default would be optional. I checked that TZ changes worked, by adding a cron job (for testing purposes) under each TZ declaration, of the form TZ=America/New_York * * * * * date /home/mysite/public_html/tmp/log.txt 21 and TZ=Australia/Sydney * * * * * date /home/mysite/public_html/tmp/log.txt 21 SNIP I propose the following: cron itself has no concept of timezone. it is 'date' that is picking up TZ and reporting as such. Cron's job is so simple is that it wakes up each minute to see if it has work to do, regardless of timezone, or anything else. You might want to try some other determining factor, such as a shell builtin. Good luck. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: Crontab for different ime zones
Is there a way to start jobs with cron using different a time-zone different from local time zone? I am in a TZ that has no Daylight Savings Time, and would like to start a job (reccording of a web cast) in a TZ that has DST (so with a time difference that changes along the year). Is there an automatic/intelligent way to do that? Not that I know of, yet since timezones only change twice a year you can look up the changes for the coming year and adjust the crontab accordingly. Hey, I am too lazyto change my crontab twice a year, and we have computers, they should do the work for us. The way I did it: - start the cron job at the earliest of both time (winter time, or summer time). - at the begining of the job, have a small Perl script that will wait until it is the specified time in the specified time zone: at best it will not wait, at worst the perl script will sit idled for one hour before giving the hand back to the real job. Et voila (well, it will be et voila once the job will have completed succesfully once :) Thanks, Olivier ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: Crontab for different ime zones
On Tuesday 31 March 2009 09:56:14 Olivier Nicole wrote: Is there a way to start jobs with cron using different a time-zone different from local time zone? I am in a TZ that has no Daylight Savings Time, and would like to start a job (reccording of a web cast) in a TZ that has DST (so with a time difference that changes along the year). Is there an automatic/intelligent way to do that? Not that I know of, yet since timezones only change twice a year you can look up the changes for the coming year and adjust the crontab accordingly. Hey, I am too lazyto change my crontab twice a year, and we have computers, they should do the work for us. Once a year, since you can use months and days. In fact, iirc DST changes are known 5 years ahead (I'm sure Ill be corrected if this is not the case) so one can even run a yearly cronjob to change the crontab ;) Of course, waiting an hour during summertime is an option, as is running cron in a jail with /etc/localtime of the target timezone - use tzsetup(8) for that inside the jail (though seems overkill for the purpose). -- Mel ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: Crontab for different ime zones
Mel Flynn wrote: .. Once a year, since you can use months and days. In fact, iirc DST changes are known 5 years ahead (I'm sure Ill be corrected if this is not the case) so one can even run a yearly cronjob to change the crontab ;) .. You might want to mention that to the Australian state governments; we've been getting a few months notice (might be a slight exaggeration, definately nowhere near 5 years!) for the last few years now :( ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Crontab for different ime zones
Hi, Is there a way to start jobs with cron using different a time-zone different from local time zone? I am in a TZ that has no Daylight Savings Time, and would like to start a job (reccording of a web cast) in a TZ that has DST (so with a time difference that changes along the year). Is there an automatic/intelligent way to do that? Best regards, Olivier ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: Crontab for different ime zones
On Tuesday 31 March 2009 06:52:29 Olivier Nicole wrote: Hi, Is there a way to start jobs with cron using different a time-zone different from local time zone? I am in a TZ that has no Daylight Savings Time, and would like to start a job (reccording of a web cast) in a TZ that has DST (so with a time difference that changes along the year). Is there an automatic/intelligent way to do that? Not that I know of, yet since timezones only change twice a year you can look up the changes for the coming year and adjust the crontab accordingly. -- Mel ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org