Stop your staggered cron jobs from killing your disk I/O
Cron & Task Scheduling (Cron/Systemd Timers/At)
Stop your staggered cron jobs from killing your disk I/O
🧩 The Challenge
You’ve got ten different database cleanup scripts scheduled to fire at exactly 12:00 AM, and every night your server turns into a brick while they fight over the disk controller. I’ve wasted so many nights debugging mysterious latency spikes that turn out to be nothing but poor timing.
💡 The Fix
Use a random delay to spread out those heavy tasks so they aren’t all crushing the CPU and disk queue at the exact same second. It keeps the system responsive and saves you from a 2 AM wake-up call.
sleep $((RANDOM \% 300)); /usr/local/bin/cleanup_script.sh
⚙️ Why It Works
Adding that short sleep command injects a bit of chaos into the schedule, effectively jittering the start time by up to five minutes.
🚀 Pro-Tip: If you’re on systemd, just set RandomizedDelaySec in your timer unit file instead of messing with bash hacks.
Linux Tips & Tricks | © ngelinux.com | 7/24/2026
