SERVER & LINUX
systemd timer & service generator
Create a systemd service – optionally with a timer as a modern replacement for cron jobs. The preview shows when an OnCalendar expression will run next, and cron expressions can be converted.
backup.service
/etc/systemd/system/backup.service
[Unit] Description=Nightly backup Wants=network-online.target After=network-online.target [Service] Type=oneshot ExecStart=/usr/local/bin/backup.sh
backup.timer
/etc/systemd/system/backup.timer
[Unit] Description=Timer for Nightly backup [Timer] OnCalendar=*-*-* 02:30:00 Persistent=true [Install] WantedBy=timers.target
Install
Copy the files to the server and run these commands in the same directory.
sudo cp backup.service backup.timer /etc/systemd/system/ sudo systemctl daemon-reload sudo systemctl enable --now backup.timer systemctl list-timers backup.timer sudo systemctl start backup.service # run once now journalctl -u backup.service -e
Frequently asked questions
Why systemd timers instead of cron?
Timers log every run to the journal (journalctl -u), catch up on missed runs with Persistent=true, avoid overlapping runs because a service only runs once at a time, and benefit from dependencies, resource limits and sandboxing of systemd services. systemctl list-timers shows when each job last ran and runs next.
How do I read an OnCalendar expression?
The format is weekday year-month-day hour:minute:second, where each part may be * (any), a list (1,15), a range (Mon..Fri, 08..18) or a repetition (00/15 = every 15 starting at 0). Omitted parts default to * for the date and 00:00:00 for the time. On the server, systemd-analyze calendar "…" shows the next runs.
Do I enable the service or the timer?
Only the timer: systemctl enable --now name.timer. The service needs no [Install] section; the timer starts it. To run the job once immediately, use systemctl start name.service.
Which time zone does the timer use?
Without a time zone in the expression, the local time zone of the server (timedatectl). Append UTC or a zone like Europe/Berlin to OnCalendar for a fixed zone. Runs that fall into a DST gap are skipped.
How do I convert a cron job?
Paste the five time fields into the converter. Two differences remain: cron runs when either the day of month or the weekday matches, systemd only when both match, and cron sends output by mail while systemd writes it to the journal. The command itself goes to ExecStart.