Set Up a systemd Timer Failure Notification for Backups and Jobs

Cron used to mail you when a job broke. You moved the backup to a systemd timer, and that mail stopped coming.

The job didn't stop failing. systemd just doesn't send anything, and the ArchWiki confirms timers have no built-in match for cron's MAILTO.

Every scheduled job, covered

FailNote alerts you when any timer's job fails, with the cause. One install command.

Start free

A timer job can go wrong in two ways

  1. It runs and fails. The service the timer starts exits with an error, so systemd marks it failed. A hook can catch this.
  2. It never runs. The timer got disabled, its unit has a typo, or the server was off. Nothing fails, so no hook fires.

You need a check for each. Most setups only have the first one, which is why backups go quiet for weeks.

Alert when the job fails

Put the alert on the service, not the timer. The timer only starts backup.service. That service is the unit that fails.

[Unit]
Description=Nightly backup
OnFailure=notify-failure@%N.service

[Service]
Type=oneshot
ExecStart=/usr/local/bin/backup.sh
TimeoutStartSec=2h

[email protected] is a small template unit that sends the alert. Our guide to a systemd alert on failure builds it and adds it to every service at once. Need it as email? See sending failure emails through a relay.

Why the timeout line matters

Type=oneshot services have no start timeout by default. A backup that hangs on a dead mount just sits there, never failing and never finishing.

TimeoutStartSec=2h turns that hang into a failure you hear about. Pick a limit well above your longest normal run. When it trips, the status shows Result: timeout.

Make the script fail loudly

systemd only knows a job failed if it exits with a non-zero code. Many backup scripts hide errors, because a shell script returns the status of its last command.

#!/bin/bash
set -euo pipefail

pg_dump mydb | gzip > /backup/mydb.sql.gz
rclone copy /backup remote:backups

set -e stops at the first error, and pipefail catches a failed pg_dump inside the pipe. Look for || true in old scripts too. It turns every failure into a success.

When a run does fail, the status line tells you how. An exit-code result means the script returned an error, and status=203/EXEC means it never started at all. Paste the status into the systemd service failure analyzer to see which checks to run.

Catch the runs that never happen

Start by checking when each timer last fired and when it fires next:

systemctl list-timers --all
systemctl show backup.timer -p LastTriggerUSec -p NextElapseUSecRealtime

If the server is sometimes off at the scheduled time, add Persistent=true to the [Timer] section. systemd then runs a missed OnCalendar= job as soon as the timer starts again.

For a real alert on missed runs, use a heartbeat check. The job pings a URL when it succeeds, and a service such as Healthchecks.io warns you when the pings stop:

[Service]
Type=oneshot
ExecStart=/usr/local/bin/backup.sh
ExecStartPost=/usr/bin/curl -fsS -m 10 --retry 3 https://hc-ping.com/YOUR-UUID

ExecStartPost= only runs after ExecStart= succeeds, so a failed backup sends no ping either. Set the expected period to match your timer, plus some grace time.

Cover every timer with FailNote

Adding OnFailure= to each job by hand is easy to forget on the next one. FailNote's agent hooks every service on the server, so every job a timer starts is covered from the moment you install it.

  • Failed runs, explained. The alert names the likely cause, such as a missing script or a bad permission, and the next command to run.
  • Hung jobs, once you set a timeout. A job killed by its time limit shows up as a failure like any other.
  • Dead servers. If the whole machine stops checking in for five minutes, you get an alert. A server that's off can't run its backups.
  • Your channels. Email, Slack, Discord, Microsoft Teams or a webhook.

To be clear about the limits: FailNote catches jobs that fail and servers that go quiet. It doesn't know a job was supposed to run at 2 a.m., so pair it with a heartbeat check for your most important backup.

It's free for one server, and Pro covers up to 10, billed monthly. The full rundown is on the FailNote page.

Start FailNote free

Enter your email. We'll send a sign-in link, and your dashboard has the install command.

Already have an account? Sign in. See our privacy policy and terms.