The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Operating Systems > SUN Solaris
.
google unix.com



SUN Solaris The Solaris Operating System, usually known simply as Solaris, is a free Unix-based operating system introduced by Sun Microsystems .

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Scheduling bi-weekly through cron LPT UNIX for Advanced & Expert Users 5 02-20-2009 10:45 AM
cron scheduling? megh HP-UX 1 08-19-2008 02:27 PM
Problem with scheduling a shell script on cygwin using cron shash UNIX for Dummies Questions & Answers 4 08-09-2007 06:08 PM
scheduling tasks with cron alikun UNIX for Dummies Questions & Answers 4 03-21-2007 03:32 PM
cron job scheduling shihabvk UNIX for Advanced & Expert Users 1 08-22-2005 10:36 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-29-2008
Registered User
 

Join Date: Sep 2008
Posts: 261
Cron job scheduling on the alternate day of the week

Hi,

Help please!

I have to schedule some job on every Monday and alternate Thursday with Cron. I am not sure as if I pass 1 and 5 on the day filed, the job will be scheduled for every Monday and Thursday. How to schedule in job in above case.

Thanks in anticipation.
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 09-29-2008
Moderator
 

Join Date: Feb 2007
Posts: 3,547
Have a read of this link regarding this stuff:

cron and crontab

Regards
Reply With Quote
  #3 (permalink)  
Old 09-29-2008
Registered User
 

Join Date: Sep 2008
Posts: 261
Hi Frank

Thanks for the link!

However my problem is still open.

From the given link
---------------------------
0 0 1-7 * 5 /some/script
You might hope that will run /some/script during the first minute of the first Friday of the month. Unfortunately, it will run the script on each day of the first week of the month and on every Friday.
----------------------

In my case I have to schedule the job on every Monday and every alternate Thursday. If the write the below code

0 0 1-7 * 1,4 <path to script>

Then above will run every Monday and Thursday, however I have to skip one week and then run the script in case of Thursday.

Please help !

Regards
Reply With Quote
  #4 (permalink)  
Old 09-29-2008
wempy's Avatar
Registered User
 

Join Date: Jun 2006
Location: Harpenden, UK
Posts: 205
A simple, though not particularly elegant, solution, is to write a wrapper script that executes your target script on the specified days, and call the wrapper script from cron.

eg (of the top of my head, not tested):
Code:
#!/bin/bash
FLAGFILE=/var/tmp/FlagFileNameThatIsUnique
DAY=`date +\%a`
case $DAY in
Mon) /path/to/script/to/be/run;;
Thu) [ -f $FLAGFILE ] && rm $FLAGFILE || (/path/to/script/to/be/run; touch $FLAGFILE);;
esac
set the cron entry to call the wrapper every monday and thursday.
The wrapper will only run the script on a thursday if the flagfile doesn't exist (and create the flagfile, once it has run). The next time it gets called on a thursday the flagfile will exist, so it doesn't run the script, just deletes the flagfile.

You may want to be careful where you store the flagfile, as on your system /tmp and /var/tmp may be 'cleaned' if the system is rebooted. You also have to ensure that the flagfile is uniquely named, so that nothing else can interfere with it.
Reply With Quote
  #5 (permalink)  
Old 09-29-2008
Registered User
 

Join Date: Sep 2008
Posts: 261
Thanks Wempy

Are we saying without having a wrapper script it’s not possible to schedule the script on alternate days of the week?
Reply With Quote
  #6 (permalink)  
Old 09-29-2008
wempy's Avatar
Registered User
 

Join Date: Jun 2006
Location: Harpenden, UK
Posts: 205
well, it is possible, but your crontab lines get awfully long. Cron will only execute EVERY set day, there is no explicit way to tell it every Other set day, so you have to test whether it should run today or not, and in the simple, binary, case like this, the easiest (maybe quickest) solution is to keep track of things with a flagfile.
You can put the logic in the wrapper script above into the cron entry, but, as I said, it makes the entry very long, and difficult to read.
Reply With Quote
  #7 (permalink)  
Old 09-29-2008
Registered User
 

Join Date: Sep 2008
Posts: 261
I appreciate you help!

Please can you let me know what will be the entry in crontab evne though its big I would like to test it.

Thanks again
Reply With Quote
Google The UNIX and Linux Forums
Reply

Bookmarks

Tags
None

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:




All times are GMT -4. The time now is 04:52 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66