How do I create a CRON job so that it runs every 15 minutes (24 hours a day) but for one week only and exits? Thanks!
Asked
Active
Viewed 695 times
1 Answers
7
Cron has no concept of week, you will have to have your script or some other script make the final decision on whether to run or not. The date command can provide the ISO week of year %V so you could do something like
*/15 * * * * test `date +\%V` == "30" && doSomething
to run a script doSomething every 15 minutes next week but it would run next year too so use
*/15 * * * * test `date +\%G\%V` == "201330" && doSomething
to limit it to this year.
Note that the %
's above are escaped with a \
it is important.
user9517
- 114,104
- 20
- 206
- 289
-
What happen if you creat cronjob on Saturday of week 30, then on Monday of week 31, `doSomething` will not run? – cuonglm Jul 17 '13 at 06:18
-
-
1
-
@Gnouc: How do you know that you're a mind reader ? I provided a method which is generally extensible. As I'm sure you know the date command is very flexible Edward could use ...+%s having pre calculated the correct number of seconds ... once you have a method the rest is easy. – user9517 Jul 17 '13 at 06:31