snooze is a program to run scheduled tasks, and its design matches exactly what I’d been wanting: snooze parses the schedule, sleeps until the desired time and finally executes the specified command.
Each task is an individual process which can be managed with the usual process management tools. This means that it is also possible to run an instance of snooze as an individual service via one’s service manager under the usual service supervision tree.
The man page describes its usage quite well, and this post describes its mode of operation and usage in greater detail. The snooze command is currently packaged by a few distributions, and its source is public domain.
A minimal usage example is the following:
snooze -H9 -M40 echo "it is now 09:40"
Note that the snooze command exits after running the command. For recurring tasks, the service manager should re-start it once it exits, preparing for the next execution. This design also ensures that there are never any concurrent executions.
As a bonus use case, snooze can be used easily schedule a one-shot which inherits the current execution environment.
Notes on cron
The snooze command’s use case overlaps with cron, but the former doesn’t depend on a service that needs to be executed by root. It kind of bothers me that cron service that needs to run as root and requires privilege escalation for a user to operate.
cronie
, dcron
, fcron
bcron
and anacron
all have the same design as
cron. It’s perfectly fine on a server, but on desktop / interactive systems, I’d
prefer something that doesn’t require any elevated privileges to enable or
operate if the tasks will run as an unprivileged user.
snooze runs entirely within the process tree of the user, without any additional privileges in any of the parts involved. It is even suitable for usage inside containers.