Cron expression that spans across next day
Asked Answered
R

1

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

Robertroberta answered 26/5, 2015 at 8:37 Comment(3)
try this: */15 8-24 * * * /home/user/command.sh and */15 0-3 * * * /home/user/command.shInterlineate
including 03:00am or not?Nawrocki
Thanks for the response. 3:00am is to be included.Robertroberta
N
8
*/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
Nawrocki answered 26/5, 2015 at 8:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.