Field Notes

systemd timers instead of cron

December 9, 2025

For a job that runs once a night, a systemd timer is a service file plus a timer file. It is more typing than a crontab line, but you get logging and status for free.

The service

# /etc/systemd/system/cleanup.service
[Unit]
Description=Nightly cleanup

[Service]
Type=oneshot
ExecStart=/usr/local/bin/cleanup.sh

The timer

# /etc/systemd/system/cleanup.timer
[Unit]
Description=Run cleanup every night

[Timer]
OnCalendar=*-*-* 03:30:00
Persistent=true
RandomizedDelaySec=300

[Install]
WantedBy=timers.target

Enable it with systemctl enable --now cleanup.timer.

The two options worth knowing

Looking at it

systemctl list-timers shows when each timer last ran and when it runs next. Output of the job goes to the journal: journalctl -u cleanup.service. To check a calendar expression before using it, run systemd-analyze calendar "*-*-* 03:30:00".

← All notes