288 points · by mooreds · 5y ago · 78 comments
$ systemd-analyze calendar "*:11/5" --iterations 3
Original form: *:11/5
Normalized form: *-*-* *:11/5:00
Next elapse: Mon 2021-08-30 23:21:00 EEST
(in UTC): Mon 2021-08-30 20:21:00 UTC
From now: 47s left
Iter. #2: Mon 2021-08-30 23:26:00 EEST
(in UTC): Mon 2021-08-30 20:26:00 UTC
From now: 5min left
Iter. #3: Mon 2021-08-30 23:31:00 EEST
(in UTC): Mon 2021-08-30 20:31:00 UTC
From now: 10min leftI prefer setting the random offset when writing/deploying the crontab (you probably have them committed somewhere so there's bound to be a deployment mechanism, such as ansible). This way the offset is kept constant, while still avoiding the "thundering" cron.
My friend and I have built an indie hacker software business, Cronitor, and we’ve been happy to give it a good home for the last three years. It’s incredibly rewarding to deliver something that millions of people find useful. Cronitor pays the bills but if I want a pick-me-up, I search crontab.guru tweets and back links and it always delights me.
For basic cron alerts, health checks is a nice free service, but you can do much much more with Cronitor!
I’ve been using fcron a lot recently as a cron replacement and its really good. Even works in non systemd systems too :D
Its 100x easier to debug , comes with a cli tool to give you info on when its gonna run , you can force it to run immediately in cli during tests and debugging of the cron job, can literally save you a loooot of time and is mostly an almost drop-in replacement of cron.
Diminutive hours
cut thirty-one Decembers:
the moon and the sun.You can literally write in crontab
@daily /script/to/run/daily
@hourly
@monthly
@weekly
@reboot
That will greatly reduce your confusion with the stars during a quick edit.I find myself using these shortcuts frequently. Only time when I don't is when I would like to separate the commands so that those all don't start together.
Well, for one thing, here are 4 completely new concepts that I don’t particularly want to bother with.
I just want to run a command every minute. I don’t want to learn about unit, timer or event files and the differences between them.
Sure, you have to learn the system's particulars and both systems have corner cases that seem to pop up in even the simplest of uses
...however, cronjobs are a single entry in a single application. Systemd is a system backbone. Using it for everything when you know how to use it is straightforward. Almost no one knows how to use it.
Another systemd "change for change's sake" argument.
I would set up a service for something that needs to be more robust and complex.
If not, I think your comment is pretty irrelevant since there are still scenarios where you'd need to use cron.
I can use them as a user and non-root, I get to use journalctl and systemd status to check if it ran. The timers run independently of others and the timers are in English.
If you are using Devuan or something weird like that then sure, but nearly every other way I find systemd-timers better especially for debugability.
That comment rubs me the wrong way. To mirror the sibling, there's a lot outside the Linux+SystemD world - even your firewall probably doesn't use systemd (or linux for that matter, if you're in a professional environment), and neither does Alpine, that runs docker containers. (And love it or hate it, docker is in a lot of commercial production stuff.)
"There are more things in heaven and earth, Horatio, than are dreamt of in your philosophy."
And Debian isn't exactly "weird".
A bit error prone perhaps, but that is why you have crontab.guru.
This is wrong because September never has 31 days. A little experimentation confirms that 31 is accepted as a valid input for all the months, while 32 is appropriately always rejected. This bug is easy to fix, as the correct length of months is easy to determine.
While fixing this, bonus points for warning users when they've scheduled a job either within the span where the time will be hit twice when the clocks roll back for Daylight Savings Time, or within the span where a job will never run on the night when the clocks are adjusted forward. [0] Also helpful to let users know when they've scheduled a job that will only run during a leap year. [1]
[0] https://stackoverflow.com/questions/13195999/daylight-saving...
[1] https://www.nbcdfw.com/weather/weather-connection/a-leap-yea...
Crontab.guru essentially applies the same validations that Vixie cron does when you save a job. If you use "crontab -e" it will let you add a job with the schedule 5 4 31 9 *, and it flags the others you mentioned as invalid. For the most part, crontab.guru tries to be true to Vixie cron.
Also, good news on the daylight savings front. As you can imagine with a service like Cronitor we had to learn a lot about this. In most modern versions of Cron, jobs scheduled with a specific time will not be replayed or skipped when the clock moves for DST. You can see the logic here:
https://github.com/svagner/vixie-cron/blob/master/cron.c#L22...
One major reason Vixie cron doesn't warn people that they've created a job which will never run, or will only run in a leap year, or whatever, is that there's no convenient way to issue the warning. The thing is configured prior to runtime via text editor. There's zero downside to anyone if you warn people they've created a job that will never run.
It's less important than the end of month warning which is so easy to fix, but the nice part about warning about jobs in the DST window is that the warning helps out everyone, regardless of whether they're using a modern version of Vixie cron. So much job-scheduling related software relies on cron syntax, and I'd venture to guess a lot of those people would be happy to use your tool, probably more than the traditional Unix administrators. Granted, it's a weird warning to word properly.
Maybe in the 22nd century.
Although:
await agenda.every("3 minutes", "delete old users");
// Alternatively, you could also do:
await agenda.every("*/3 * \* \* \*", "delete old users");
Cron would do something different here. The second expression would run every third minute. 0:00, 0:03, ...not exactly "every 3 minutes".
I will painfully admit I hassle with going from PT/PDT --> UTC more than I should, but after a while it was pretty easy to commit a simple number of hours (+7/8, depending on daylight savings timing) to memory.
I used to use [Hour](https://apps.apple.com/us/app/hour-world-clock/id569089415?m...) for MacOS to avoid this problem; I'm sure there's a similar or native solution for Windows & Linux as well.
I am not recommending this.
https://stackoverflow.com/questions/34357126/why-crontab-use...
there is also 'remind': https://dianne.skoll.ca/projects/remind/
which is very flexible, unfortunately it hasn't really made it into the 'canon'
I never check the "new" page, but this is the first time I've seen it and I've been reading HN almost daily for over half a decade. 2-3 years before Rust went 1.0 at least.
/var/log/cron on RHEL and SLES systems:
# cat /var/log/cron
Aug 1 03:47:18 ssds9 run-parts(/etc/cron.daily)[19200]: finished logrotate
Aug 1 03:47:18 ssds9 run-parts(/etc/cron.daily)[19068]: starting man-db.cron
Aug 1 03:47:19 ssds9 run-parts(/etc/cron.daily)[19211]: finished man-db.cron
Aug 1 03:47:19 ssds9 run-parts(/etc/cron.daily)[19068]: starting rpmdiff.sh
Aug 1 03:47:44 ssds9 run-parts(/etc/cron.daily)[19225]: finished rpmdiff.sh
Aug 1 03:47:44 ssds9 anacron[18489]: Job `cron.daily' terminated (produced output)
Aug 1 03:50:01 ssds9 CROND[19260]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Aug 1 04:00:01 ssds9 CROND[19384]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Aug 1 04:01:01 ssds9 CROND[19403]: (root) CMD (run-parts /etc/cron.hourly)
Aug 1 04:01:02 ssds9 run-parts(/etc/cron.hourly)[19403]: starting 0anacron
Aug 1 04:01:02 ssds9 run-parts(/etc/cron.hourly)[19412]: finished 0anacron
So yes it’s posted often, but not as often as "more than once at month".