Generate crontab for odd time intervals

222 Views Asked by At

I am planning to monitor some values in a system between time intervals. I am implementing quartz scheduler. I wanted to understand how to generate crontab which will have the following attributes:

  1. Runs between 9:45- 12:30
  2. Interval - 15 mins
  3. Weekdays

The closest I was able to get was

0/45 9-12 * * Mon-Fri

which is roughly “At every 0 and 45th minute past the 9, 10, 11 and 12th hour on Mon, Tue, Wed, Thu and Fri.”

1

There are 1 best solutions below

0
Luca Ghersi On

I don't think you can use a cron string to set at the same time a minute interval and a minute start / end. For example, you can do this:

0 0/15 9-11 ? * MON-FRI

to run every 15 minutes between 9 and 12 (11.59) or this

0 15 9-12 ? * MON-FRI

to run at 9.15, 10.15 etc.

What I suggest you is to use more than 1 cron schedule using multiple triggers, as suggested here. Or, even simpler, do not use cron but use the TriggerBuilder utility.

Hope it helps :)