?
Solved

setting up cron jobs for different time zone

Posted on 2003-11-25
8
Medium Priority
?
743 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 400 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses
Course of the Month14 days, 18 hours left to enroll

771 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