[CentOS] setup schedule cron job every other week?

John R Pierce pierce at hogranch.com
Wed Jan 6 00:18:23 UTC 2010

mcclnx mcc wrote:
> We have CENTOS 5 on DELL server.  I tried to setup schedule cron job to run every other week on Saturday (NOT first and third week ).

lets see...

date +'%U'

returns the week number of the year, 00-51... and (( expression ))
evaluates arithmetic expressions, returning 'true' if they are non-zero.
weeknumber & 1 will be 0 for even weeks and 1 for odd weeks.

So... set up your cron job to run every Saturday, and in the beginning
of the job script, do something like...

(( $(date +'%V') & 1 )) && exit

which will exit if the week of the year is even. or, in the front of
your crontab line, something like....

30 1 * * 6 (($(date +'%V')&1)) && command-you-want-to-execute-on-even-weeks

More information about the CentOS mailing list