Preventing Task Overlap with Systemd RunOnce
Cron & Task Scheduling (Cron/Systemd Timers/At)
Preventing Task Overlap with Systemd RunOnce
🧩 The Challenge
Standard cron jobs often trigger concurrently if a previous process is still running, which can lead to resource contention or data corruption.
💡 The Fix
Use systemd transient units with the CollectMode option to ensure that tasks execute sequentially or cleanup automatically after completion.
systemd-run --unit=backup-job --on-calendar="*-*-* 03:00:00" --remain-after-exit=no --collect=inactive-or-failed /usr/local/bin/backup.sh
⚙️ Why It Works
The –collect flag instructs systemd to automatically remove the service unit once the process exits, preventing the accumulation of stale job states while keeping execution logs available.
🚀 Pro-Tip: Use systemctl list-timers to verify the next scheduled execution time for your transient unit.
Linux Tips & Tricks | © ngelinux.com | 7/9/2026
