Site icon New Generation Enterprise Linux

Keep your systemd timers from silently failing in the shadows

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

Keep your systemd timers from silently failing in the shadows

đź§© The Challenge

You finally moved your messy cron jobs over to systemd timers, but now you have no idea if they actually did anything. It’s annoying to dig through systemctl status logs every time a backup job doesn’t finish.

đź’ˇ The Fix

You can add an OnFailure directive to your service file to trigger a secondary unit whenever your primary job crashes. This is a lifesaver for getting alerts before your users complain that the data is stale.

[Unit]
Description=My Critical Task
[Service]
ExecStart=/usr/local/bin/backup.sh
OnFailure=status-email-admin@%n.service

⚙️ Why It Works

Adding an OnFailure hook tells systemd to invoke a specific unit only when the main process hits a non-zero exit status. It turns silent failures into actual events you can monitor.

🚀 Pro-Tip: Keep your alert service dead simple; just have it curl a webhook or shoot an email so you aren’t chasing ghosts.

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

0 0 votes
Article Rating
Exit mobile version