For prior art (not GPT-3 based) in debian/ubuntu based distributions:
/usr/share/doc/cron/examples/crontab2english.pl
I use to use it like: perl /usr/share/doc/cron/examples/crontab2english.pl /etc/cron.d/myfile
Also prior to crontab.guru: $ head -2 /usr/share/doc/cron/examples/crontab2english.pl
#!/usr/bin/perl
#Time-stamp: "2001-07-29 16:07:28 MDT"
21 years ago, more people did prefer english to cron :)Sometimes I am astonished what has been sitting in my directories all these years.
The biggest one probably being the 15 minutes it took to learn how to write systemd service files, versus using <language-specific-process-monitor-and-daemon>.
Any chance it could be made into a library/api?
This will come as an unpleasant surprise when you try to schedule something to run on, say, the first Friday of the month.
There are workarounds, mostly involving backticked date invocations, but they’re hard to both write and read.
0 0 */50,1-7 * FRI
It works, but it's a bit of a hack (to put it mildly ;-) )
Consider this expression:
0 0 1-7 * FRI
This one will run on dates 1-7, and additionally on every Friday. This is almost what we want, except we want an "AND" relationship between the day-of-month and the day-of-week fields, instead of the "OR" relationship.
The weird extra */50 bit exploits a quirk in Debian cron's expression parsing logic. It fools cron into thinking the day-of-month field is a wildcard field, and into applying the "AND" logic.
I'd love a CLI version of this tool, where I pass in the cron expression and it tells me the english translation.
Check out Cronstrue[1], its what I use for going from cron expression to english.
Let me know if you get any interesting results!
Scheduled tasks are hard enough to debug as it is. The last thing I want to do is add more indeterminism!
It was designed to be easy to fit most things into one line.
It can express pretty much everything imaginable. But it's not designed to do that easily.
Maybe it'd be better to come up with a schema that's better suited for expressing non-trivial crons - and converting that to & from crontab format.
English is also not the best language for expressing this type of thing...
We have created structured, unambiguous domain languages for a reason. Converting from English is ambiguous at best, impossible at worst.
Maybe an alternative to natural language processing could be pattern recognition from a number of user supplied examples, and its expression in an unambiguous domain language. That's also what programmers do.
... nice. Other folks are beating ya up based on their first try but mine was exactly correct!
Adding to my cron tools bookmarks - cool stuff.
"The second Sunday of every month except in December"
0 0 8-14 1-4,6-12 *
IMO it should generate something like: "0 0 * 1-11 SUN#2"
The "#2" bit is not standard cron syntax though and will not work correctly in e.g. Debian cron.
I tried other hard ones and got rate limited :(
"0 0 * * * *" (Every hour)
So I believe this robot is quite happy -- way happier than average mortal humans.I made a similar tool [1] to convert English to Excel formulas but would def take a page out of your super clean look!
Every 15 minutes except at 3AM?
Stackoverflow responses say it can't be done in one line.
I can't think of a way to get it in one line. Probably easiest is to split into two jobs.
*/15 1,2,4-23 * * * - this runs every 15 mins except between 3am and 4am
15,30,45 3 * * * - this should cover the delta
"At 12:00 AM, on day 31 of the month, only in February"
Not precisely related, just a go-to "they've thought of that" anecdote for when people are underestimating how thorough the law can be.
Sometimes: “Every hour”
Once in a blue moon: “At 12:00 AM, on day 18 of the month, only in February”
On my birthday: “At 12:00 AM”
On Christ's birthday: “At 12:00 AM, on day 25 of the month, only in December”
Not sure if it gave right results. but i think this is amazing stuff. Thanks for building it.
"When the stock market closes and opens" - I think the stock market opens at 9:30 though, not 9.
Still some more work, methinks.
"first and third Tuesday at noon each month "
> 0 2 3,5,7 * *
Not great
> 0 2 3,5,7 * *
We gotta stop crediting junk as interesting.