DailyGlimpse

Replacing Cron with Systemd Timers: A Technical Guide

Opinion
May 17, 2026 · 3:15 AM

Replace Cron with Systemd Timers: A Step-by-Step Guide

In this lesson, we explore how to replace the traditional cron scheduler with systemd timers on Ubuntu. Systemd timers offer more flexibility and integration with the rest of systemd, making them a powerful alternative for scheduling tasks.

Key Concepts

  • OnCalendar Syntax: Define recurring schedules using a format similar to cron but more expressive. For example, Mon..Fri 10:00 runs every weekday at 10 AM.
  • Persistent=true: Ensures that missed tasks (e.g., due to system downtime) are run as soon as the system is back up.
  • RandomizedDelaySec: Adds a random delay to prevent all systems in a fleet from running a task simultaneously, reducing load spikes.

Example Timer Unit

Create a timer file at /etc/systemd/system/mytask.timer:

[Unit]
Description=My custom timer

[Timer]
OnCalendar=Mon..Fri 10:00
Persistent=true
RandomizedDelaySec=10min

[Install]
WantedBy=timers.target

Then create a corresponding service file mytask.service that defines what to execute. Enable and start the timer:

sudo systemctl enable mytask.timer
sudo systemctl start mytask.timer

Benefits Over Cron

  • Better logging and monitoring via journalctl.
  • Dependency handling and conditional execution.
  • Easier to manage with systemd's ecosystem.

By switching to systemd timers, you gain more control and visibility over scheduled tasks in modern Linux environments.