intro: timer(1) - run command at a specific interval
timer [-w] [-c clockid] interval command [arguments...]
At some point I got a bit annoyed with how cron would always mean
sending an email on command output, even for things like munin-cron
which typically runs every 5 minutes.
Plus what seems to be rather awkward error handling, specially for
directories like /etc/cron.daily containing multiple
scripts where if one fails the others wouldn't be ran.
So wrote a timer command, which simply launches
a single command at a specified internal relative to itself,
rather than at a human time.
It is very basic, and not meant to be a cron replacement, see bottom
of article for those, but more like an alternative model.
Also in the effects that might be interesting to some when compared to other similar tools:
- Can specify a clock other than realtime, which can make it more predictable. And on systems with
*_ALARMclocks like Linux, allowing the machine to wake up. - Doesn't interacts with the filesystem, so works well for embedded devices or immutable systems
- Unlike systemd timers it isn't linked to an ecosystem, so can be used with your favorite supervisor (say OpenRC, s6, runit, …) or even none for throwaway timers
- Exits when the command wasn't successful, so failures can be easily supervised
Links
Examples
munin-cron
#!/sbin/openrc-run
supervisor=supervise-daemon
command="timer"
command_user="munin"
command_args="5m munin-cron"
export SSD_NICELEVEL="20"
export SSD_IONICELEVEL="3:7" # I7
mirroring
Note: uses foreground and execlineb commands from execline instead of using shell
#!/sbin/openrc-run
supervisor=supervise-daemon
command="timer"
command_user="haelwenn"
# Better pass -w to not munch I/Os right when system is probably still somewhat booting up
command_args="-w 1d foreground execlineb -c /git/mirror/update.eb '' sh /tank/kopimi/mirror/update.sh"
export SSD_NICELEVEL="20"
export SSD_IONICELEVEL="3:4" # I4
Similar cron-alternative tools
- Leah Neukirchen's snooze: Sleeps until matching scheduled human-time, where it then execs into a command instead of spawning it
- Paul Jarc's runwhen: Sleeps until time computed with few supporting utilities, allows both machine-time and human-time, where it then execs into a command instead of spawning it
- Uwe Ohse's uschedule: Central per-user daemon, very cron-like (Or it's maintained version by JdeBP)