Wednesday Dec 24, 2008

Timezone aware cron finally pushed to OpenSolaris

With this “push” yesterday:

changeset:   8439:51a23ac0d2a6
user:        Chris Gerhard <Chris.Gerhard@sun.com>
date:        Tue Dec 23 15:44:14 2008 +0000
files:       usr/src/cmd/cron/Makefile usr/src/cmd/cron/cron.c usr/src/cmd/cron/cron.h usr/src/cmd/cron/crontab.c usr/src/cmd/cron/funcs.c
description:
PSARC/2007/503 crontab entry environment variables
6518038 cron & crontab should support multiple timezones

OpenSolaris finally contains a version of cron that understands and correctly handles having different timezones. You can also specify a different home directory (useful when you don't want NFS to get involved in your cron job for any reason) and shell to run jobs in. It should be in build 106 of OpenSolaris & Nevada.

This brings you crontab in line with at(1) which has been timezone aware for some time.

To use simply set the variables HOME, TZ and SHELL in your crontab file and all subsequent lines will use those values until the next HOME, TZ and SHELL lines are found:

SHELL=/usr/bin/ksh
TZ=Africa/Abidjan
HOME=/tmp/cg13442
23 \* 1-9,11-26,28-29,31 2-10,12 \* exec /var/tmp/cron/crontest.sh.1.1 23 \\\* 1-9,1
1-26,28-29,31 2-10,12 \\\* Africa/Abidjan
HOME=/var/tmp/cg13442
3 0-7,9-10,12-22 1-6,8-9,11-21,24-26,28 1-7,9-10,12 \* exec /var/tmp/cron/crontes
t.sh.1.1 3 0-7,9-10,12-22 1-6,8-9,11-21,24-26,28 1-7,9-10,12 \\\* Africa/Abidjan
TZ=Africa/Accra
37 0-2,4-5,7-17,20-22 \* \* \* exec /var/tmp/cron/crontest.sh.1.1 37 0-2,4-5,7-17,2
0-22 \\\* \\\* \\\* Africa/Accra

Tuesday Jan 23, 2007

Mutliple time zones for cron

I've never worked out why things happen in pairs but last Friday two timezone related issues came up. One a server running in some US timezone while serving services to all the world prompted my blog entry to suggest that you run your servers in GMT post. However there was also a question about cron, which featured in the follow up to my post. That is cron run in the timezone of the system. Not the timezone of the users or a arbitrary timezone chosen by the user. Would it not be cool to be able to specify a timezone in your crontab file? Better yet let you specify multiple timezones in crontab files eg: z

TZ=US/Pacific
\* 11 \* \* \* (/usr/bin/date ; /usr/bin/date -u) > /tmp/cron.out
\* 19 \* \* \* (/usr/bin/date ; /usr/bin/date -u) > /tmp/cron.out19
\* 15 \* \* \* (/usr/bin/date ; /usr/bin/date -u) > /tmp/cron.out15
\* 8 \* \* \* (/usr/bin/date ; /usr/bin/date -u) > /tmp/cron.out8
TZ=GMT
\* 15 \* \* \* (/usr/bin/date ; /usr/bin/date -u) > /tmp/cron.out15gmt


So the first four crontab lines would run in US/Pacific and the last in GMT. Each user can use as many timezones as they wish and the TZ environment variable is propergated to the child.


Now as it happens I am travelling so that has meant a few hours in Airports and I got wondering how easy it would be to get cron to be more timezone friendly.

The answer to this is it takes just over one Tecra M2 battery life to get it working. Clearly this needs some more testing , and the crontab command needs to validate the TZ strings rather than just past them though. but the diffs are here. The output file shows one of the runs from US/Pacific:

6 # cat /tmp/cron.out8
Tue Jan 23 08:25:00 PST 2007
Tue Jan 23 16:25:00 GMT 2007
7 # 

Now I need to file an RFE and see if this can be putback.

Tags:

About

This is the old blog of Chris Gerhard. It has mostly moved to http://chrisgerhard.wordpress.com

Search

Archives
« April 2014
MonTueWedThuFriSatSun
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    
       
Today