Cron & Task Scheduling (Cron/Systemd Timers/At)
Stop systemd timers from hiding your exit codes
đź§© The Challenge
Dealing with a timer that fails silently is a special kind of hell, especially when you think the backup script actually ran because the service shows as active. You stare at the status output and everything looks green, but the data is nowhere to be found.
đź’ˇ The Fix
Add a specific directive to your timer unit to force the system to track the exact result of the last execution, making it visible to standard monitoring tools. It keeps you from having to dig through journald logs just to see why the job exited with a non-zero code.
[Service]
Type=oneshot
ExecStart=/usr/local/bin/backup-script.sh
SuccessExitStatus=0
Restart=on-failure
RestartSec=5m
⚙️ Why It Works
Setting the restart policy on a oneshot timer tells systemd to treat a crash or a failed exit as a state change you need to be alerted about, rather than just burying the failure under a successful “inactive” state. It turns that invisible error into a hard status you can’t miss.
🚀 Pro-Tip: Use systemctl list-timers –all to see if your timers are actually failing in the background before the next run rolls around.
Linux Tips & Tricks | © ngelinux.com | 8/18/2026
