Cron & Task Scheduling (Cron/Systemd Timers/At)
Stop your systemd timers from running tasks out of sync
🧩 The Challenge
Setting up a timer to run every hour sounds fine until you realize it fires exactly one hour from whenever you enabled it, rather than at the top of the hour. Then you end up with logs staggered across twelve different boxes, making correlation an absolute nightmare.
💡 The Fix
Use the OnCalendar directive in your timer unit file instead of OnUnitActiveSec to anchor your tasks to specific wall-clock time points. It forces the system to align execution to a predictable schedule, which is exactly what you need for log rotation or data syncs.
[Timer]
OnCalendar=hourly
AccuracySec=1m
⚙️ Why It Works
Setting the calendar field tells systemd to calculate the next trigger time based on the actual clock rather than a relative offset from when the service last ran. By throwing in a small AccuracySec value, you stop the kernel from trying to align every single timer on the server to the exact same millisecond and slamming your CPU.
🚀 Pro-Tip: Run systemd-analyze calendar hourly to check exactly when your next few jobs are scheduled to fire.
Linux Tips & Tricks | © ngelinux.com | 8/3/2026
