Solved

setting up cron jobs for different time zone

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
forget admin password 8 23
Help stop mail server from sending spam. 27 117
reinstall 1 56
text in table need to be center of the box 4 67
When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.

758 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