upvote

  $ 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
reply
So 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.

reply
I, er, what? It's... the same as cron? I'm confused now. It's not exactly the same, I guess?
reply
Something 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/syst...

reply
It'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.
reply
Sure, 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/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.

reply
If you know the syntax, it's still actually rather trivial. Still easier to read than advanced cron magic.
reply
> 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.

reply
That'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
reply
`* 1 * * * sleep $(( $(od -N1 -tuC -An /dev/urandom) \% 45 ))m ; <your command here>`
reply
> 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>

reply