Stop cron jobs from nuking your server’s load at midnight
Cron & Task Scheduling (Cron/Systemd Timers/At)
Stop cron jobs from nuking your server’s load at midnight
🧩 The Challenge
Everyone schedules their heavy database maintenance scripts for exactly midnight, and then acts surprised when the server grinds to a halt every single night. I’ve spent way too many early mornings debugging why the web stack timed out just because someone didn’t add a little jitter.
💡 The Fix
Use a random sleep command inside your crontab entry so the execution drifts, keeping your CPU and disk I/O from spiking all at once. It’s the easiest way to stagger tasks without moving to systemd timers.
0 * * * * root sleep $((RANDOM \% 600)); /usr/local/bin/cleanup-logs.sh
⚙️ Why It Works
Adding the sleep variable forces the shell to wait for a random number of seconds between zero and ten minutes before firing off the actual script. By the time it hits the cron spool, the burstiness is smoothed out across the whole interval.
🚀 Pro-Tip: If you’re doing this in a shell script, define the sleep at the top so it doesn’t clutter your actual logic.
Linux Tips & Tricks | © ngelinux.com | 10/30/2026
