Search code examples
linuxunixcronscheduling

How to instruct cron to execute a job every second week?


I would like to run a job through cron that will be executed every second Tuesday at given time of day. For every Tuesday is easy:

0 6 * * Tue

But how to make it on "every second Tuesday" (or if you prefer - every second week)? I would not like to implement any logic in the script it self, but keep the definition only in cron.


Solution

  • How about this, it does keep it in the crontab even if it isn't exactly defined in the first five fields:

    0 6 * * Tue expr `date +\%W` \% 2 > /dev/null || /scripts/fortnightly.sh