Issue
I'm pretty new to using crontab. I have a requirement to schedule an airflow DAG that should run every hour starting at 21:00 on every Saturday and run till 04:00 on Sunday.
i.e it should run according to the below schedule:
21:00 on Saturday(18th June 2022)
22:00 on Saturday(18th June 2022)
23:00 on Saturday(18th June 2022)
00:00 on Sunday(19th June 2022)
01:00 on Sunday(19th June 2022)
02:00 on Sunday(19th June 2022)
03:00 on Sunday(19th June 2022)
04:00 on Sunday(19th June 2022)
The next iteration should start on Saturday(25th June 2022) at 21:00
I tried using the below expression but it's showing invalid:
0 21-23,0-4 * * 6-0
Solution
You cannot have multiday spanning ranges set in single crontab entry because crontab file syntax is very limited and it simply does not support that. In your current form you would end up having job run also every Sunday 21:23 hrs too. The simplest workaround is to create two separate entries: first one for Saturday and 2nd one for Sunday, so there's no way of any overlap and ambiguition:
0 21-23 * * 6
0 00-04 * * 0
Answered By - Marcin Orlowski Answer Checked By - Robin (WPSolving Admin)