Ditch Cron for Systemd Timers to Stop Missing Execution Windows
Cron & Task Scheduling (Cron/Systemd Timers/At)
Ditch Cron for Systemd Timers to Stop Missing Execution Windows
🧩 The Challenge
You ever have a cron job that runs at 3 AM but takes just long enough to overlap with the next day’s start, turning your server into a churning pile of disk I/O misery? I spent a whole weekend debugging a race condition because crond doesn’t care if your last job is still alive.
💡 The Fix
Use a systemd timer unit with the OnActiveSec and OnUnitActiveSec directives instead of the crusty old cron syntax. It forces the task to wait for the previous run to fully exit, preventing those nasty overlaps.
[Unit]
Description=Run my script reliably
[Service]
ExecStart=/usr/local/bin/backup.sh
[Timer]
OnCalendar=*-*-* 03:00:00
AccuracySec=1m
Persistent=true
[Install]
WantedBy=timers.target
⚙️ Why It Works
Setting the unit up this way decouples the schedule from the execution logic, and because it relies on systemd, you get actual logging in journald instead of guessing if the job died in a `/dev/null` void.
🚀 Pro-Tip: Always enable the timer with –now so you don’t forget to actually start the sequence.
Linux Tips & Tricks | © ngelinux.com | 7/12/2026
