Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to find a way to cron a job so that it runs every second wednesday of the month. Is this possible?

share|improve this question

migrated from Jun 20 '11 at 15:21

This question came from our site for professional and enthusiast programmers.

This question looks to provide an appropriate answer. – scurker Jun 20 '11 at 14:16
Yeah, but that question's about Tue, not Wed ;) The accepted answer is clever, though. – edoloughlin Jun 20 '11 at 14:22
>> Yeah, but that question's about Tue, not Wed ;) The accepted answer is clever, though ... what is so hard to change Tue to Wed ? – ajreal Jun 20 '11 at 14:33
0 * * * 3 test $(date \+%u) -eq 3 && echo "start run me" try this. didn't paste to the answer because one liner question is pretty vague. – Jasonw Jun 20 '11 at 14:53

My manpage for crontab (which I sadly can't seem to find online) gives the following example:

# Run on every second Saturday of the month
0 4 8-14 * *    test $(date +%u) -eq 6 && echo "2nd Saturday"

Adapting this to your purposes...

0 4 8-14 * *    test $(date +%u) -eq 3 &&
share|improve this answer
To anyone looking to edit this answer, the reason you don't just use the day of week field is that if both day of month and day of week are restricted (ie, aren't *), the command will run when either one matches. – Hasturkun Jan 24 '13 at 18:51

It's not possible using cron on its own, but you could call a script once a week that does the test:

In crontab, run at 12.00 every Wednesday:

0 12 * * 3 /home/you/bin/


#!/usr/bin/env bash
day_of_month=`date +"%
if [ $day_of_month -gt 7 -a $day_of_month -lt 15 ]; then
  # Call your program here instead of 'ls'…
share|improve this answer
Wouldn't it be a bit more straight forward to use the fifth field (day of week)? No need to call it on the other days. – Fredrik Jun 20 '11 at 14:25

You can do this directly with cron:

# Run every 2nd Wednesday at noon
# Minute: 0
# Hour: 12
# Day of month: 8-14 (2nd week, in other words)
# Month: any
# Day of week: Wednesday (3)

0 12 8-14 * 3 echo '2nd Wednesday'
share|improve this answer
Did you even try that first? Crons run 'in addition', not exclusive. That will run every 8-14 AND every Wednesday – ppostma1 May 19 at 18:44

Based on this answer, you could do:

00 12 * * Wed expr `date +\%d` \> 7 \& `date +\%d` \< 15 >/dev/null &&
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.