Site icon New Generation Enterprise Linux

Give your long-running cron tasks a hard deadline

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

Give your long-running cron tasks a hard deadline

🧩 The Challenge

You ever have a backup script or a data sync that hangs forever, locking your database tables or filling up your disk because it never actually finished? It’s a classic headache that eats up resources until you finally notice the load spike hours later.

💡 The Fix

Wrap your command in the timeout utility so the system kills it automatically if it takes longer than your threshold. It saves you from manual intervention when things go sideways.

timeout 30m /usr/local/bin/sync-db.sh

⚙️ Why It Works

Setting a duration forces a SIGTERM on the process if the clock runs out, which keeps your schedule from cascading into a total system stall. It effectively stops the zombie process before it ruins your day.

🚀 Pro-Tip: Use the -k flag if you want to send a forced SIGKILL signal after the initial timeout to ensure the process actually dies.

Linux Tips & Tricks | © ngelinux.com | 12/6/2026

0 0 votes
Article Rating
Exit mobile version