by galkk · 3y ago · 0 comments
I need to write a cron expression like once in couple years. So, I don't have working memory of it. So, to write it, I need to
1. Google "cron run something periodically".
2. Filter spam such as geeksforgeeks and irrelevant stackoverflows
3. Find either good enough approximation
4. If didn't work, go to cron man and start reading it. Example that I look for is 3rd from below in examples table https://docs.oracle.com/cd/E12058_01/doc/doc.1014/e12030/cro...
OR
I can go to chatgpt/copilot and directly ask what I need
"Tell me a cron expression to run command on each third Monday of a month and explain it"
and it will give me good enough approximation right from the start. I won't need to fight popups that will shame me for using adblockers, I won't need to go through tons of spam. I will get much better headstart, that will save my time and energy.
ChatGPT responds:
> 0 0 0 ? * MON#3 *
Regarding MON#3, it explains: "Day of the week (MON#3): This is the crucial part of the expression. We use MON to specify that we want the command to run on a Monday. Then we append #3 to indicate that we want the third occurrence of Monday. This ensures that the command will run on the third Monday of the month."
It does not mention though, even with the smallest hint, that standard cron does not support this syntax. Or a 7-field syntax.
(By "standard cron" I mean Vixie cron derivatives like the one that ships with Debian)
The correct answer in this case would have been: "This is not possible with standard cron syntax alone. You can either use a different cron implementation that supports MON#3, or schedule for every Monday, but then in your script check if it's the third Monday."
I'd rather use something like https://crontab.guru/ to verify my syntax, thus I have it bookmarked for the 1-2 times a year it comes up.
An LLM is probably the only thing which could tell you this.