5

My job requirement is: 1.Every 15 minutes 2.Everyday morning 8:00am to next day 03:00am

So the job keeps runs every 15 min from 08:00 am to next day 03:00 am.

Can this be achieved using a cron expression.

Tried this but it does not seem to help.

0 0/15 8-3  * * ?

Thanks, Wajid

wajid mehraj
  • 263
  • 3
  • 14

1 Answers1

7
*/15 0-2,8-23 * * *  test.sh
─┬── ───┬──── ┬ ┬ ┬
 │      │     │ │ │
 │      │     │ │ │
 │      │     │ │ └───── day of week (all)
 │      │     │ └─────── month (all)
 │      │     └───────── day of month (all)
 │      └─────────────── hour (between 0-2 and between 8-23)
 └────────────────────── min (every 15 minutes)

Run every 15 minutes, from 12:00am to 02:45am and from 08:00am to 23:45 of every day.

0-2,8-23 is equivalent to 0,1,2,8,9,10,...,23 while */15 is equivalent to 0,15,30,45.

The above will not include 03:00, because the last execution would be 02:45; if we use 0-3 instead of 0-2, it would have also executed at 03:15,30,45.

To be able to include also 03:00,(02:59 actually) we need to be a bit more verbose:

14,29,44,59 0-2,8-23 * * *  test.sh
guido
  • 18,864
  • 6
  • 70
  • 95