Today is Friday, October 3, 2014 3:58 AM
I want to schedule a cronjob like that to run it at the following dates:
- Saturday, October 4, 2014 8:00 AM
- Saturday, October 18, 2014 8:00 AM
- Saturday, November 1, 2014 8:00 AM ... ...
So every 2 weeks , on Saturday, at 8 o'clock.
date +%W
: week number of year with Monday as first day of week, today week 3910#$(date +%W)
: conver thedate +W
to decimal number and avoid shell base parsing confusion$((39%2))
: modulo operation: result is 0 (even week number) or 1 (odd week number), this week result is 1, next week 0test 1 -eq 1
: arithmetic test (equal), in this case result is boolean true&& yourCommand
: Boolean AND: runyourCommand
only if result of previous command was boolean trueNote that the year can get two odd weeks: 53 (this year) and 1 (next year)
What you've shown is "every week". Then the code is:
Are you sure you need to run it every two weeks?