A: 

Run it on the 1st, 2nd, 4th (and maybe 5th, it can happen) weekends.

# m h dom      mon dow   command
  * * 1-20,28-31 *   0     echo #test

I have no idea if that will run everyday, or just on Sundays (day 0), but it won't run on the 21st to 27th - the third week. It may be simple enough to put a check in the script that will exit if it is the third week (or it's not a Sunday).

Alister Bulman
This won't actually work (at least not with vixie cron). This will cause the script to run on days 1-20, 28-31, *and* every Sunday. When dom and dow are specified, the script is run when either condition succeeds.
Sean Bright
I stand corrected - but a check in the script for a 'not-sunday, so exit' would solve that. Then again, so would running it every sunday, and then exiting if was the 21st-27th.
Alister Bulman
A: 

If you want it to run on any possible Saturday except the third one (try #3):

GREP=/usr/local/bin/grep
TODAY=/bin/date "+%d"
THIRD_SAT=/bin/date -v1d -v+1m -v-7d -v-sat "+%d"
#min hr day month weekday script
0    0  *   *     6       ($THIRD_SAT | $GREP $TODAY) || /bin/echo doit
Rick C. Petty
This won't actually work (at least not with vixie cron). This will cause the script to run on days 1-13, 21-31, *and* every Saturday. When day of month and day of week are specified, the script is run when either condition succeeds.
Sean Bright
Thanks for pointing that out. I hadn't realized the last two columns are ORed instead of ANDed. Learn something new every day!
Rick C. Petty
A: 
  1. make a cron job that runs a given script when needed ignoring the 3rd weekend part
  2. make a cron job that runs on the 21 and another on the 28 to switch the script out and back for another no-op script.

Hacky but it would work

BCS
+1  A: 

Save the following as /usr/local/bin/is_third_week_in_month.sh or some place

#!/bin/bash

if [ $# != 3 ]
then
    echo "Usage: $0 <yyyy> <mm> <dd>" 1>&2
    exit 127
fi

YEAR=$1
MONTH=$2
DAY=$3

FIRST_WEEK_IN_MONTH=`date +%V -d $YEAR-$MONTH-01`
WEEK_FOR_DAY=`date +%V -d $YEAR-$MONTH-$DAY`

DIFF=$(($WEEK_FOR_DAY - $FIRST_WEEK_IN_MONTH))

if [ $DIFF = 2 ]
then
    # this is the third week
    exit 0
else
    exit 1
fi

and then add to crontab

12 00 * * 1,2,3,4,5  your_command
12 00 * * 6,7  test ! /usr/local/bin/is_third_week_in_month.sh `date "+%Y %m %d"` && your_command

Or you could modify the script to check for date as well if you want to only have one line in crontab.

hlovdal
On my system, date +%V prints a leading zero for single digit week numbers. That makes the calculation of $DIFF think it's got octal values and fail. Try running this script for 2009 02 19, for example. Strip the leading zero as follows: FIRST_WEEK_IN_MONTH=`date +%V -d $YEAR-$MONTH-01|sed s/^0//` --- and on the next line --- WEEK_FOR_DAY=`date +%V -d $YEAR-$MONTH-$DAY|sed s/^0//`
Dennis Williamson
Also, the ISO week number (%V) for Jan 1 can be 52 (e.g. 2006) or 53 (e.g. 2005) which can cause th $DIFF calculation to be negative and fail to find week 3 in January. So you should change the "%V"s to "%W" which always starts the year in week zero or one and ends the year in week 52 or 53 (%V can end the year in 52, 53 or 1).
Dennis Williamson