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

link|improve this question
This question looks to provide an appropriate answer. – scurker Jun 20 '11 at 14:16
1  
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
feedback

migrated from stackoverflow.com Jun 20 '11 at 15:21

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

3 Answers

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 && job.sh
link|improve this answer
feedback

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 second_wed.sh at 12.00 every Wednesday:

0 12 * * 3 /home/you/bin/second_wed.sh

In second_wed.sh:

#!/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'…
  ls
fi
link|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
feedback

Based on this answer, you could do:

00 12 * * Wed expr `date +\%d` \> 7 \& `date +\%d` \< 15 >/dev/null && runJob.sh
link|improve this answer
feedback

Your Answer

 
or
required, but never shown