Unix administration - crontab entries for different time zones?

This is Interesting: Free IT Magazines  
Home > Archive > Unix administration > June 2004 > crontab entries for different time zones?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author crontab entries for different time zones?
hymie!

2004-06-02, 4:51 pm

Greetings.

A problem has arisen at my workplace. We are near Baltimore, MD,
GMT-5/GMT-4, and we have a customer in Honolulu, HI , GMT-10.

I would like to run a cron job on my Solaris 9 box every day at 0800 HST.
The Solaris box has EST5EDT as its default time zone. Unfortunately,
half of the year, 0800 HST = 1400 ET, and the other half,
0800 HST = 1300 ET.

Is there a way that I can somehow attach a TZ variable to an individual
crontab entry?

The only thing I can think of that would work is to run my job every
day at 1300 EST/EDT , and start my script with

if [ `date +%Z` = "EDT" ]
then
sleep 3600
fi

but the actual job is just a mv , and I was hoping to avoid building
a script around it.

Thanks.

hymie! http://www.smart.net/~hymowitz hymie@lactose.smart.net
========================================
=======================================
Mark Rafn

2004-06-02, 4:51 pm

hymie! <hymie@lactose.smart.net> wrote:
>I would like to run a cron job on my Solaris 9 box every day at 0800 HST.
>The Solaris box has EST5EDT as its default time zone. Unfortunately,
>half of the year, 0800 HST = 1400 ET, and the other half,
>0800 HST = 1300 ET.
>Is there a way that I can somehow attach a TZ variable to an individual
>crontab entry?


Not in the way you want. The TZ var can be set in an entry, but it's
passed through to the job, and has no effect on when the job runs.

>The only thing I can think of that would work is to run my job every
>day at 1300 EST/EDT , and start my script with
>if [ `date +%Z` = "EDT" ]
>then
> sleep 3600
>fi
>but the actual job is just a mv , and I was hoping to avoid building
>a script around it.


Another option would be to just edit the crontab in April and November. If
you want to get tricky, you can write a cron job which runs 2 hours before the
main job (only needed to run in November and April), and rewrites the crontab
if the DST has changed.

Or just move it to 1000 ET, which is the middle of the night in Hawaii and
they won't care about the one hour difference.
--
Mark Rafn dagon@dagon.net <http://www.dagon.net/>
*doesn't get to wear his BOFH hat often enough*
Birger Blixt

2004-06-04, 4:53 pm

On 2004-06-02 20:37, hymie! wrote:[vbcol=seagreen]
> Greetings.
>
> A problem has arisen at my workplace. We are near Baltimore, MD,
> GMT-5/GMT-4, and we have a customer in Honolulu, HI , GMT-10.
>
> I would like to run a cron job on my Solaris 9 box every day at 0800 HST.
> The Solaris box has EST5EDT as its default time zone. Unfortunately,
> half of the year, 0800 HST = 1400 ET, and the other half,
> 0800 HST = 1300 ET.
>
> Is there a way that I can somehow attach a TZ variable to an individual
> crontab entry?
>
> The only thing I can think of that would work is to run my job every
> day at 1300 EST/EDT , and start my script with
>
> if [ `date +%Z` = "EDT" ]
> then
> sleep 3600
> fi
>
> but the actual job is just a mv , and I was hoping to avoid building
> a script around it.
>
> Thanks.
>
> hymie! http://www.smart.net/~hymowitz hymie@lactose.smart.net
> ========================================
=======================================[
/vbcol]

Cron will only use one timezone, at last what I beleive.

Create a cronjob that run a (write protected) script at the morning your time.

In the script you can try:

#!/bin/sh

TZ=HST
export TZ

at 8 << EOF >/dev/null 2>&1

cd something
mv foo bar
.....

EOF

Then your atjob will follow another timezone.

demo :-)

% cat htest
#!/bin/sh

TZ=HST
export TZ

at 8 << EOF

date >/tmp/htest


EOF

% ./htest
commands will be executed using /bin/tcsh
job 1086372000.a at Fri Jun 4 08:00:00 2004
% setenv TZ EST5EDT
% at -l
1086372000.a Fri Jun 4 14:00:00 2004
%

This example will run the job at 08:00:00 HST whatever the EST5EDT time is.

% zdump EST5EDT HST
EST5EDT Fri Jun 4 11:30:19 2004 EDT
HST Fri Jun 4 05:30:19 2004 HST


/bb
Jay Lessert

2004-06-09, 8:06 am

hymie@lactose.smart.net (hymie!) wrote in message news:<10bs7k5ihfl7041@corp.supernews.com>...
> but the actual job is just a mv , and I was hoping to avoid building
> a script around it.


A wrapper is the only correct/robust way to do it.

Might be better to have the wrapper actually check
Hawaii time, and just run it every hour:

TZ=US/Hawaii; export TZ
hour=`date +%H`
if [ $hour -eq 8 ] ; then
mv foo bar
fi

Then in the future when either of the zone definitions change,
the crontab takes care of itself
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com