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.
Maybe a little dumb, but one could also create two cronjobs, one for every first tuesday and one for every third.
First cronjob:
Second cronjob:
Not sure about the syntax here, I used http://www.cronmaker.com/ to make these.
pilcrow's answer is great. However, it results in the fortnightly.sh script running every even week (since the epoch). If you need the script to run on odd weeks, you can tweak his answer a little:
Changing the 1 to a 0 will move it back to even weeks.
Cron provides an 'every other' syntax "/2". Just follow the appropriate time unit field with "/2" and it will execute the cronjob 'every other time'. In your case...
The above should execute every other Tuesday.
If you want every tuesday of second week only:
00 06 * * 2#2
What about every 3rd week?
Here's my suggestion:
... or ...
... or of course ...
... depending on the week rotation.
Syntax "/2" is not goes along with weekday. So my added to the smart above is simply use 1,15 on MonthDay filed.
0 6 1,15 * * /scripts/fornightly.sh > /dev/null 2>&1