[Solutions] Run cronjob every other Saturday

We just had this problem and no "obvious" solution:
How to run a cronjob every other Saturday?
The first step is easy, run a cronjob every Saturday:
Then we thought about "guessing" when the first and third Saturday would be:
This works "mostly", but will fail about twice a year. So in the end we run the script every Saturday and add this snippet:
rm -f /etc/job/runme
else
touch /etc/job/runme
exit -1
fi
...
This will run your cronjob once every other Saturday.
EOF
Back home
12:16:12 15.02.2010 | Permalink | Trackback URI
foo (2010-02-15 23:17:56)
0 0 * * 6 expr `date +%j` % 3 >/dev/null && /usr/local/bin/job.bash
(untested)
foo (2010-02-15 23:19:43)
"% 2", of course.
Your comment was not sent
Possible reasons: You left a column blank, the comment is too short or you tried to spam me.
Note that referer spoofing also makes it impossible to post a comment.
Your comment will be held for moderator approval.
blindcoder (2010-02-16 12:00:45)
@foo:
Unfortunately, that will not work over a year change. For example take the change 2010/2011:
blindcoder@fortuna:~$ date -d 20101225
Sat Dec 25 00:00:00 CET 2010
blindcoder@fortuna:~$ date -d 20110101
Sat Jan 1 00:00:00 CET 2011
blindcoder@fortuna:~$ date -d 20101225 +%j
359
blindcoder@fortuna:~$ date -d 20110101 +%j
001
blindcoder@fortuna:~$ expr `date -d 20101225 +%j` % 2
1
blindcoder@fortuna:~$ expr `date -d 20110101 +%j` % 2
1
This would cause the script to run at two consecutive Saturdays. On other years, it might cause the script to NOT run at two consecutive Saturdays.
foo (2010-02-16 21:46:03)
Hmm, right..
But this should:
`date +%s` / 86400 % 2
I don't like the /etc/job/runme file..


