All guides
Cron jobs·3 min read

RECIPE: SYSTEMD TIMER

Monitor a job scheduled with a systemd timer.

1

Create the service

Save as /etc/systemd/system/backup.service:

[Unit]
Description=Nightly backup

[Service]
Type=oneshot
ExecStart=/bin/sh -c '/opt/backup.sh && curl -fsS -X POST "https://upguru.io/api/push/YOUR-TOKEN" -d "done" || curl -fsS -X POST "https://upguru.io/api/push/YOUR-TOKEN?level=error" -d "backup failed"'
2

Create the timer

Save as /etc/systemd/system/backup.timer:

[Unit]
Description=Run the backup every night

[Timer]
OnCalendar=*-*-* 02:00:00
Persistent=true

[Install]
WantedBy=timers.target
3

Turn it on

sudo systemctl daemon-reload
sudo systemctl enable --now backup.timer
systemctl list-timers backup.timer
Run sudo systemctl start backup.service once to test it without waiting for the night.