1

so I have a task I need to schedule, it needs to be ran every 10 minutes, from monday to friday between 10am and 8pm.

So far, I'm using this expression :

0 */10 10-19 * * mon-fri

Note : this is a Spring expression, but I believe the classic cron expression would be the same without the first 0 for the seconds. Is that Correct ?

The issue with this expression is that it runs correctly except for the 8pm, the last occurrence is 19:50 and not 20:00.

How could I fix this and make it run one more time ? Also I Believe it does, but to make sure, it will also run at 10:00 ?

Mahmoud Ben Hassine
  • 28,519
  • 3
  • 32
  • 50
Ellone
  • 3,644
  • 12
  • 40
  • 72
  • 1
    It's not possible to achieve the desired result with 1 cron. for the final 20:00 run you'r going to need a seperate cron line. `0 0 20 * * mon-fri`. And to confirm yes your given cron wil run at 10:00, basicly it says run when day is between mon-fri, hour is between 10-19 and minutes can be divided by 10. See https://stackoverflow.com/questions/41743720/crontab-run-every-15-minutes-between-certain-hours for a simulair issue – Ralan Oct 17 '22 at 13:01
  • Oh, so it's not possible in one expression :(, thanks for your input. – Ellone Oct 17 '22 at 13:04

2 Answers2

0

So like Ralan commented, it is apaprently not possible to do this in one cron expression. The simplest solution is to add another expression matching the missing hour at minute 0.

Ellone
  • 3,644
  • 12
  • 40
  • 72
0

In a classic cron job, the right expression for such job would be as follow:

0,10,20,30,40,50 10-20 * * 1-5

where:

0,10,20,30,40,50: At minute 0, 10, 20, 30, 40, and 50

10-20: hours

* : day of month (1-31)

* : month

1-5: monday to friday

samivic
  • 1,216
  • 14
  • 13