How to schedule a biweekly cronjob?

Solution 1:

You can have the thing run by cron every wednesday, then have the thing run decide if it is an even week or an odd week. for example:

week=$(date +%U)
if [ $(($week % 2)) == 0 ]; then 
    echo even week
    echo odd week

Solution 2:

Many crons (you didn't specify which you're using) support ranges. So something like

0 0 1-7,15-21 * 3

Would hit the first and third wednesdays of the month.

Solution 3:

For something that needs to run every other week use this one-liner:

0 0 * * 5 [ `expr \`date +\%V\` \% 2` -eq 0 ] && echo "execute script" 

This particular script is scheduled to run on Fridays. The week to be executed on can be adjusted by using "-eq 0" or "-eq 1"

Solution 4:

If your needs aren't literally bi-weekly, you could simply run the cronjob on the 1st and 15th of the month:

15 8 1,15 * * /your/

Which runs at 8:15 a.m. on the first and fifteenth of each month regardless of the day of the week.