Skip to content
Advertisement

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.

Advertisement

Answer

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
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement