You can write a wrapper script, to make it only run for every 2nd week, and put it in the crontab to run the script once a week, please have a look at my example script in http:Q_20607871.html
Main Topics
Browse All TopicsHello,
Can anybody help me out in setting the cron-job for every 2 weeks (on sunday), lets say I want run restart-server.sh script.
Can some one give exact format for this. like 0,15,30,45 * * * * /tmp/restart-server.sh
Thanks,
AJ
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
You can write a wrapper script, to make it only run for every 2nd week, and put it in the crontab to run the script once a week, please have a look at my example script in http:Q_20607871.html
OK, no problem.
Let's go from inside out.
- but first the backslashes ( \ ) - they're needed to protect the "%" signs from being interpreted by cron. Please look at "man crontab" for an explanation.
"date +\%W" gives the week number starting with zero (37). "+" indicates the start of a so called field descriptor, "%W" being only one of many. Use "man date" to learn about the other ones.
The $( ... ) means, in simple words, "execute the command inside and replace the whole $(...) thing with the result"
So at the first stage the above reads [ $((37\%2)) -eq 1 ] &&
$(( ... )) indicates an arithmetic operation. "%" means "divide and return the remainder". Again, the whole $((...)) stuff is replaced by the result (37%2=1 - "37 divided by two gives 18 remainder 1")
So, at stage two, we have [ 1 -eq 1 ] &&
"-eq" is a comparison operator and means "arithmetically equal"
"[ ... ] &&" is a short form for "if [ expression ] then ...". In other words: "if the comparison inside the brackets returns a "true" result, execute the next command"
So our stage three reads: "If one is equal to one then execute the command following "&&""
"1 -eq 1" is obviously "true".
Thus in our current week 38 (which is week 37 for the "date" command) "/tmp/restart-server.sh" would be executed, whereas next week (38%2 is 0, which is not equal to 1) it wouldn't.
I think you're familiar with the crontab syntax (the 00 04 * * 0 .... stuff)? If not, again please look at "man crontab", where it's well explained.
Hope I could help you a bit,
have fun!
wmp
Business Accounts
Answer for Membership
by: svingalPosted on 2009-09-15 at 15:57:52ID: 25340442
i think this is not possible by cron.
schedule your script every week, and use this little script which makes it run the "action"-part only every other run:
On the first run the script will not find /some/file, so it will create it and exit. On the second run it will remove it and then proceed to do whatever it is supposed to do. On the next run it won't find the file (because it removed it) and therefore will only create it and then exit, ....
This script can be used weekly in cron but will do its intended purpose only every other week.
Select allOpen in new window