Site icon New Generation Enterprise Linux

Stop letting your cron jobs overlap and hammer your disk

Cron & Task Scheduling (Cron/Systemd Timers/At)

Stop letting your cron jobs overlap and hammer your disk

đź§© The Challenge

You ever have a backup job that takes longer than expected and ends up colliding with the next run, turning your I/O into an absolute disaster? It’s a nightmare to debug once the logs start piling up.

đź’ˇ The Fix

Use a lockfile pattern with flock to make sure only one instance of the script runs at any given time, regardless of how slow your disk gets. It’s the easiest way to prevent a resource death spiral.

* * * * * /usr/bin/flock -n /tmp/backup_job.lock /usr/local/bin/run_heavy_backup.sh

⚙️ Why It Works

The -n flag tells flock to fail immediately if it can’t acquire the lock, effectively skipping the execution instead of stacking processes on top of each other.

🚀 Pro-Tip: Add a simple logger or wall command to the failure branch so you know when it’s actually skipping runs.

Linux Tips & Tricks | © ngelinux.com | 11/29/2026

0 0 votes
Article Rating
Exit mobile version