4 ms·
"You just put numbers aligned with the titles." That is not a fair summarization of their point because that is not the grammar. There's commas, slashes, aster
by jerf 4mo ago
"You just put numbers aligned with the titles."
That is not a fair summarization of their point because that is not the grammar. There's commas, slashes, asterisks, combinations, and then if you want randomization you need to put it in the command itself because cron can't do it. (Some crons can, but it's not a general capability of cron.) Writing a non-trivial cron spec is not easy.
- eqvinox 4mo agoHow do you express those things in a systemd timer? E.g. run something 4x per day, */6 in cron.
- iam-TJ 4mo ago$ systemctl cat public-inbox-watch@.timer # /etc/systemd/system/public-inbox-watch@.timer [Unit] Description=Periodic fetch of public mailing list [Timer] # twice a day OnCalendar=*-*-* 5,17:35 RandomizedDelaySec=1h Persistent=true [Install] WantedBy=multi-user.target
- eqvinox 4mo agoI, er, what? It's... the same as cron? I'm confused now. It's not exactly the same, I guess?
- PenguinCoder 4mo agoSo the `OnCalendar` stanza is the same as a Cron job; without the helpful comments of the ordering? And that is considered _easier_?? Just use Cron. It does one thing and does it well.
- paradox460 4mo agoThe systemd one supports timezones. You can say America/Denver and the like, or Etc/UTC
- simoncion 4mo ago1) Your production equipment doesn't have its TZ set to UTC? Enjoy dealing with the intermittent and irregular hassle of DST changes, I guess. 2) From the crontab(5) on my system: The CRON_TZ variable specifies the time zone specific for the cron ta‐ ble. The user should enter a time according to the specified time zone into the table. The time used for writing into a log file is taken from the local time zone, where the daemon is running. If you have a job you need scheduled in a different timezone, dump a new file in /etc/cron.d, alter its CRON_TZ variable and go to town, as it were.
- ecnahc515 4mo agoSomething like: OnCalendar=00/6 You can test it with: systemd-analyze calendar --iterations=6 '0/6:00:00' The format is `DayOfWeek Year-Month-Day Hour:Minute:Second` https://www.freedesktop.org/software/systemd/man/latest/systemd.time.html https://www.freedesktop.org/software/systemd/man/latest/syst...
- PunchyHamster 4mo agoThat's simple but consider "run something 4x per day but randomize a delay by hour so all of the 200 servers doing that task won't run it all at once" In cron, you basically have to either use your configuration management to generate those times, or have a random delay script running before the command In systemd timers, it's just OnCalendar=0/6:00:00 RandomizedOffsetSec=60m and the offset generated will be stable for the job on a given machine (i.e. always same on this machine but different on others) so you will get nice uniform distribution of load. If you add Persist=true the job will also be run once if there was one or more scheduled runs when the machine was down
- simoncion 4mo ago> In cron, you basically have to either use your configuration management to generate those times, or have a random delay script running before the command Nope. From crontab(5) The RANDOM_DELAY variable allows delaying job startups by random amount of minutes with upper limit specified by the variable. The random scal‐ ing factor is determined during the cron daemon startup so it remains constant for the whole run time of the daemon. That's from my cronie install, but it looks like this has been a feature of some crons for at least a decade. (Notice that the post date of [0] is in 2016.) Given that cronie is based on vixie-cron, and I think I was was using vixie-cron in 2002, I bet it's been a thing for at least twenty years. [0] <https://stackoverflow.com/a/34815984 https://stackoverflow.com/a/34815984>
- PunchyHamster 4mo agostill not a thing in vixie cron installed by default in Debian in 2026. I'll take payout from your lost bet now https://dyn.manpages.debian.org/experimental/cron/crontab.5.en.html https://dyn.manpages.debian.org/experimental/cron/crontab.5....?
- PenguinCoder 4mo ago`* 1 * * * sleep $(( $(od -N1 -tuC -An /dev/urandom) \% 45 ))m ; <your command here>`
- simoncion 4mo agoSure, I'll pile on here. To do nontrivial scheduling you'd use the entirely-obvious-and-intuitive syntax described at [0]. For example: Mon,Fri *-01/2-01,03 *:30:45 Who'd ever want to go back crontab format for nontrivial scheduling? [1] [0] <https://www.freedesktop.org/software/systemd/man/latest/systemd.time.html#Calendar%20Events https://www.freedesktop.org/software/systemd/man/latest/syst...> [1] This question is sarcasm. SystemD is often like this... dead simple things look dead simple, but complex things are -if they're possible at all- at least as complex as they are everywhere else.
- p0358 4mo agoIf you know the syntax, it's still actually rather trivial. Still easier to read than advanced cron magic.
- simoncion 4mo ago> Still easier to read than advanced cron magic. Looking at the other examples on that page, I'm gonna say that it's only arguably easier to read for basic stuff... especially if you're familiar with the syntax. The complex stuff is -at best- just as difficult.
- harshreality 4mo agoI found the systemd time spec syntax you referenced to be logical and well thought out. Cron syntax is simpler for the easy cases because cron tries to do less. It ignores years and seconds entirely, and doesn't try to adhere roughly to ISO8601 ordering and field separators, instead using space universally for field separation and euro-style least-to-most significant field ordering. I like ISO8601, so I get along with systemd's style better, despite it introducing slightly more cognitive load. The only thing that threw me for a loop and seems like "special magic" was > "Mon *-05~07/1" means "the last Monday in May." But good luck doing that in one line in cron. Some cron-style libraries seem to support L/W/# for last / nearest-weekday / nth of month, but I don't know if any system crons do. (cronie? dcron? I don't think so. fcron? bcron? I don't see it there either.) '#' is syntactic sugar for DOW + 7-day range, while L is covered by the above quoted syntax. If your cron has that kind of syntax, then for a case like "weekday closest to 1st of month", "W" is more convenient than writing 3 systemd timer rules to cover the three cases (weekday day 1, monday day 2, friday last day of month), but that's a big if. Generally you'd have to write 3 rules in cron anyway.
- max-privatevoid 4mo agoIt's a mystery to me why everyone tries to use OnCalendar here, when "n amount of times within a certain timeframe" can be done much more easily with OnActiveSec, in this case that'd be OnActiveSec=6h.
- pkal 4mo agoI am familiar with the syntax, so I am biased ("*/3" and "12,14,20" makes sense if you are familiar with Unix tools), but it is still more intuitive to me than the systemd unit file syntax and usage. I know that I just have to edit /etc/cron or throw any executable file into /etc/cron.d/monthly and it will work on my system, but I cannot write a systemd timer file from scratch without looking it, and to do that I first have to find the directory where the other examples are located. /etc/systemd doesn't appear to be it. This is generally my only real complaint about systemd. I don't care if it is too monolitic, written in C or whatever, I just want a straightforward syntax for straightforward operations. I'd like it if systemd could recognize if a .target file is a shell script and just do "the right thing". Perhaps it would make sense for a timer file to recognize cron syntax as well. Or at least allow for a kind of extensibility so that I can have it supported. If systemd had a little more respect for existing conventions, I am pretty sure it wouldn't be so controversial. After all, system administrators like it because they use it all the time, but a regular, full-timer user like me, who only deals with it when something is broken or have to use it as a means-to-an-end to set something up, then all friction is annoying and bad UX. (And no, using Nix is not the solution)
- krunck 4mo agoYeah, it would be nice to have a folder like /etc/systemd-jobs/ where I could put them and where there are no files unrelated to job scheduling. There is /etc/systemd/user, but it does get a bit of pollution depending on the system.
- ralferoo 4mo agoNot sure if you're talking about cron or systemd, but cron definitely has that in /etc/cron.d where you can have arbitrary crontabs, or /etc/cron.{hourly|daily|weekly|monthly} where you can just place arbitrary scripts if you don't care exactly when they run, just the frequency.
- weaksauce 4mo agoyou can organize them however you want on your system and then use symlinks to make them available. there's also `systemctl --all list-timers` to view them.