Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

setting up cron jobs for different time zone

Posted on 2003-11-25
8
Medium Priority
?
745 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

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…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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.
Suggested Courses

618 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