[Gllug] Crontab schedule question

Benedikt Heinen gllug at ml.icemark.net
Thu Nov 17 15:15:23 UTC 2005


>>> 0 12 * * 1/2

>>> do the job?

>> That'll run it at 12pm every Monday, Wednesday and Friday.
> Wouldn't that be

> 0 12 * * */2

> I am just guessing here.

Nope - that's also calling the script every other day of the week (5th 
column is day of week). If the weekday isn't important you should be able 
to try for

 	0 12 */14 * *

Or - but even that wouldn't go strictly every other week (it could during 
month changes skip another week, might be  (hope I'll have this correct):

 	0  12  1-7,15-21 *  1

which should run your script on every Monday that is on a 1st-7th of a 
month, and every Monday that is a 15th-22nd of a month. But - there will 
be months with two Mondays in the period between 22nd-31st of the month. 
So if you can live with the occasional skip, the above should work.

If you can't live with a skip of a week, but could live with occasionally 
running two consecutive weeks, you could adapt it into

 	0  12  1-7,15-21,29-31 *  1

just to make it run the extra time at the end of the month.

Apart from that, you'd need to run your job from within a wrapper script 
that touches a flag file, whenever it runs the wrapped script, but will 
always first check whether the flag file is older than say 13 days... Such 
a script could then be run every monday, but it would still only actually 
do the work you want every other week...

another approach, also using a wrapper script would be to check whether 
it's an odd or even week (e.g. for sh:

 	wk=`date +%W`
 	if [ `expr $wk % 2 ` == 1 ]; then
 	  # odd week number
 	  ./doYourStuff -whateverflags and parameters necessary
 	fi

This, though, would once a year re-introduce the problem mentioned earlier 
(depending on whether there is a Monday - or whatever weekday is chosen - 
in the last couple of days in the year or not)



Benedikt

   ALLIANCE, n.  In international politics, the union of two thieves who
     have their hands so deeply inserted in each other's pockets that
     they cannot separately plunder a third.
 			(Ambrose Bierce, The Devil's Dictionary)
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list