yzzu5a
Last Updated: February 25, 2016
·
15.76K
· kevindew
A648ba69f706bb00f5cac9490c10f1ac

Running a Cron Job every other week

You can't specify in the cron schedule for the day of week to be divided unlike some of the other schedules, nor can you use the # to get consistent results.

The answer is to use an epxression in cron command:

0 10 * * 1 [ `expr \`date +\%s\` / 86400 \% 2` -eq 1 ] && <my command>

This will run this command every monday and by determining whether it's an odd or even day since the unix epoch will run the command

To determine whether a command would run on a specific day use the following command:

expr `date +%s -d "today"` / 86400 \% 2

a 1 means it will run a 0 means it won't. Adjust the -eq 1 to -eq 0 to adjust the day the command runs on.

Say Thanks
Respond

3 Responses
Add your response

9273
00056bab2f5f07bc37fce9d878fe45e7

Hi,

how do i set this up to run every other friday?

over 1 year ago ·
9274
A648ba69f706bb00f5cac9490c10f1ac

the 1 in 0 10 * * 1 specifies Monday so adjust this to be 5 for Friday (0 10 * * 5)

over 1 year ago ·
17708
Unnamed1

Try a cron job generator at http://www.crontab-generator.org/, very good.

over 1 year ago ·
Filed Under