Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

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

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

1 Answer 1

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
share|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

Your Answer

 
discard

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

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