3

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?

1 Answer 1

4

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
3
  • 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, 2011 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, 2011 at 9:08
  • 1
    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, 2011 at 8:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .