Schedule cron jobs to run every 2 weeks

There is no straight forward way to schedule a cron job so that a certain command gets executed biweekly, let’s say every 2 sunday nights…

To be able to do this, you need to extend your cron command with a command that tests the day of the week.

In my case I needed to perform a ‘clone MySQL database’ on the 2nd and 4th sunday of each month to a sandbox environment.

This is how I’ve implemented this:

30 2 8-14,22-28 * * test $(date +%u) -eq 1 && sh /root/clone_to_sandbox.sh

You see that the cron job itselfs is scheduled to happen from:

The 8th until 14th of each month and from the 22nd until the 28th of each month.

When executing, I test if the day is the 1st of the week (Sunday = day 1 of the week). When this result is positive, the shell script will be executed.

4 thoughts on “Schedule cron jobs to run every 2 weeks”

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top