Shashank Vashistha
Shashank Vashistha

Reputation: 131

Cron Expression for running a job at different intervals at different hours

I want to schedule a job to run every 5 mins during morning (4-8)AM and evening (7-11)PM and rest of the day every 30 minutes, how can i write a cron expression for it?

I can do this by using two cron expressions for scheduling, but can i do the task using one expression?

Upvotes: 1

Views: 3003

Answers (2)

firfin
firfin

Reputation: 355

The timings (or intensity) are different, so you need different expressions.

So something like the following is needed:

*/5 4-7,19-22 * * * your/command
*/30 0-3,8-18,23 * * * your/command

Upvotes: 1

Biscuits
Biscuits

Reputation: 1807

No, I believe you'll need 2 separate CRON expressions.

Upvotes: 4

Related Questions