Solved

setting up cron jobs for different time zone

Posted on 2003-11-25
8
741 Views
Last Modified: 2013-12-16
Hi, I'm trying to set up a cron job between two different time zones.  My machine is on GMT, but the machine that the cron will run on is on CST.  Is there a way to have the cron daemon use GMT instead of CST to initiate the job?

I know that I can set the TZ environment variable inside my script that can be used once the cron starts.  But what I really need is for the cron daemon to recognize the start time based on GMT and not CST.

Any ideas?
0
Comment
Question by:dabeast78
8 Comments
 
LVL 24

Expert Comment

by:shivsa
ID: 9819391
u can setup time in cron with the calculation with respect to your timezone.
l
0
 

Author Comment

by:dabeast78
ID: 9820247
Yeah, I was hoping for a "cleaner" way to do it so that I don't have to adjust it each time for daylight savings...
0
 
LVL 24

Accepted Solution

by:
shivsa earned 100 total points
ID: 9821062
u can try something like this.
u can put timezone information in the a script, and within script u can set it to run what time depending upon your timezone differences and all.

this is very tricky so u have to make sure that it works.

0 23 * * * if [ `env TZ=$TZ`  = 01 ] ; then your_command ; fi
-----

and like this perl script which run the job on every last day of the month.

#!/usr/bin/perl -w

#sec min hour mday mon year wday yday isdst

(undef,undef,undef,$dom,undef,undef,undef,undef,undef) =

localtime(time+24*3600);

# $dom is day-of-month for 24 hours in the future

if ($dom == 1) {

# Do what you want <<< put your script here.
}

=================
0
 
LVL 38

Expert Comment

by:yuzh
ID: 9822081
Sorry, you can not run a cron job use the TIMEZONE other than your system
default TIMEZONE.

The workaround is very simple, all you need to do is to adjust your crontable,
to make it happen.

(+- hrs)

eg, I'm at Perth, and I want to run a job use the Syndey time , let's 4pm,
and it is 1pm at Perth. all I need it to set the job start at 1pm.



0
 
LVL 62

Expert Comment

by:gheist
ID: 9828170
you can run cron in different time zone than your machine eg.
kill -TERM `cat /var/run/cron.pid`
TZ=UTC cron
or on the other hand - run system in GMT, which includes syslog and cron, and use some global user profile to set user TZ=WET or so...
some cron implementations can set variables right in crontab:
SHELL=/bin/ksh
TZ=UTC
PATH=/sbin:/bin:/usr/sbin:/usr/bin
0 0 0 0 0 /usr/bin/nice /bin/sh /home/you/minutescript
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

730 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