Replacing cronjobs with systemd timers

While cron is among the oldest, most well known job scheduling mechanisms for Unix systems, systemd also supports running scheduled jobs in the form of timer units.

Compared to traditional cron, this has various benefits:

  • Jobs can be started independently from their timers - great for debugging and other out-of-band triggers.
  • systemd supports more flexible and more powerful schedule expressions (see systemd.timer(5) and systemd.time(7)).
  • It’s much easier to define the environment a job should run in. This includes users, path, environment variables, etc. (see systemd.exec(5) for details).
  • Resource limits can be configured, making it easy to avoid excessive CPU, memory or IO usage.
  • Jobs can be set up to depend on other systemd units.
  • The status of running timers and their associated services can be monitored like any other system service, with output automatically being captured and logged to the systemd journal.
  • systemd timers don’t overlap, removing the need for manual concurrency control.