3 ms·
Guile syntax to run every second Sunday of the month (example taken directly from the manual https://www.gnu.org/software/mcron/manual/mcron.html#Every-second-S
by mrb 8y ago
Guile syntax to run every second Sunday of the month (example taken directly from the manual https://www.gnu.org/software/mcron/manual/mcron.html#Every-second-Sunday https://www.gnu.org/software/mcron/manual/mcron.html#Every-s...):
(job (lambda (current-time)
(let* ((next-month (next-month-from current-time))
(first-day (tm:wday (localtime next-month)))
(second-sunday (if (eqv? first-day 0)
8
(- 14 first-day))))
(+ next-month (* 24 60 60 second-sunday))))
"my-program")
Meanwhile in cron (second Sunday falls between the 8th and 14th day of the month, and it is the 7th day of the week):
0 0 8-14 * * [ `date +\%u` = 7 ] && my-program
I think I'll stick with cron.
- JD557 8y agoCouldn't that cronjob simply be: 0 0 8-14 * 0? (I think 0 is Sunday)
- mrb 8y agoNo because the dom field (8-14) and dow field (0) are treated as a logical OR by cron, not AND.
- gnulinux 8y agoI can't see how second syntax is better than the first one. I've never used GNU mcron but I know exactly what the first code is doing.
- xelxebar 8y agoThis is a nice misrepresentation. Your Vixie cron example offloads the day of week check to `date`. I'm sure there are examples where mcron syntax is superior to anacron as well. I didn't know about mcron until this post either, but I find it super frustrating when people dismiss tools, ideas, or people simply because they don't conform to familiar patterns.
- deleted 8y ago[deleted]
- JdeBP 8y agoTime specifications, as employed by Uwe Ohse's uschedule and systemd, encode such a rule as uschedule my-job "Sun *-*-8,9,10,11,12,13,14" OnCalendar=Sun *-*-8..14