I need to run a cronjob every 14 days on a friday i. e. every second friday. Following is the closest I can think of:

0 10 */14 * 5

I think crontab would run this cronjob at 10:00 on the 14th and 28th day of a month (and that's not even every 14 days!) if this day is a friday. This condition would not be met every second friday, of course.

Any ideas?

link|improve this question
feedback

migrated from stackoverflow.com Nov 17 '11 at 13:58

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

1 Answer

up vote 1 down vote accepted

Crontab does not support every other friday types of specification natively, but you could do something like this I suppose:

00 10 1-7,15-21 * * [ `date +\%a` = Fri ] && yourcommand
link|improve this answer
The day range is a good idea. Why are you checking for friday with shell scripting? Shouldn't 00 10 1-7,15-21 * 5 do the same? – Leif Nov 14 '11 at 13:41
I don't know, it would make sense indeed but I never tried that solution. I know for sure that /2 does not work for weekdays although that would have been the most logical solution in my view. – PhilipCB Nov 15 '11 at 9:08
It looks like the values are not all restrictive. 00 10 1-7,15-21 * 5 ran 7 times between December 1 and 7. And additionally it runs on every friday. – Leif Dec 9 '11 at 8:33
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.