[CentOS] setup schedule cron job every other week?

John R Pierce pierce at hogranch.com
Wed Jan 6 20:28:54 UTC 2010


> 0 0 * * 6 [ $((`date +"%d"`%14)) -ge 8 ] && script.sh
> Would that work?
>   


0 0 * * 6 [ $((`date +"%V"`&1)) ] && script.sh

would work better.     except, uh oh....  what happens at the end/beginning of a year?   its quite possible for the even numbered weeks in one year and the even weeks in the next year NOT to be every other week. 

this is harder than it looks.   I think you'll need to calculate total days since epoch date, modulo 14

	[ $(( ($(date +"%s") / 86400) % 14)) -eq 9 ]

where  %s is seconds since 1970-01-01 00:00:00 UTC, which was a Wednesday here (PST) at least.




More information about the CentOS mailing list