Solved

setting up cron jobs for different time zone

Posted on 2003-11-25
8
737 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 61

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
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…
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.

911 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

21 Experts available now in Live!

Get 1:1 Help Now