Site icon New Generation Enterprise Linux

Stop letting your cron jobs run forever because you forgot to add a timeout

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

Stop letting your cron jobs run forever because you forgot to add a timeout

🧩 The Challenge

You know the pain of a script that usually takes ten seconds to run suddenly hanging on a network mount or an unresponsive API. The next day, you look at your server and realize you’ve got twenty copies of that same script piled up, eating all your CPU.

💡 The Fix

Throw a timeout wrapper around your cron commands so the system kills them if they drag on too long. It keeps your process list clean and stops zombies from devouring your resources.

* * * * * timeout 300 /usr/local/bin/backup-sync.sh

⚙️ Why It Works

Adding the timeout prefix forces the command to send a SIGTERM if the timer expires before the process finishes. It’s an easy safety net for when your scripts decide to go off the rails.

🚀 Pro-Tip: Use timeout -k to send a follow-up SIGKILL if the process is stubborn and refuses to die gracefully after the initial signal.

Linux Tips & Tricks | © ngelinux.com | 8/28/2026

0 0 votes
Article Rating
Exit mobile version