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!
1 Answer
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.
-
What happen if you creat cronjob on Saturday of week 30, then on Monday of week 31,
doSomething
will not run?– cuonglmJul 17, 2013 at 6: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.– user9517Jul 17, 2013 at 6:31