Cron to systemd timer converter

Paste a crontab line to get a .timer file with the matching OnCalendar= schedule and a .service file that runs your command, plus the systemctl commands to install them.

Free, and it runs in your browser: nothing you type here is sent anywhere.

  • The command uses shell features or a relative path, so it runs through /bin/sh -c. Redirects like >> log are not needed: systemd keeps the output in the journal.

backup.timer

[Unit]
Description=Timer for backup

[Timer]
OnCalendar=Mon..Fri *-*-* 02:30:00
Persistent=true

[Install]
WantedBy=timers.target

backup.service

[Unit]
Description=backup (converted from crontab)

[Service]
Type=oneshot
ExecStart=/bin/sh -c "/usr/local/bin/backup.sh --full >> /var/log/backup.log 2>&1"

Install and check

sudo mkdir -p /etc/systemd/system
sudo cp backup.service backup.timer /etc/systemd/system/
systemd-analyze calendar "Mon..Fri *-*-* 02:30:00"
sudo systemctl daemon-reload
sudo systemctl enable --now backup.timer
sudo systemctl list-timers backup.timer
journalctl -u backup.service

How to convert a crontab line to a systemd timer

  1. Paste one crontab line, or press Load example.
  2. Set a unit name, and choose system or user scope. Add a user for system services that should not run as root.
  3. Copy or download the .timer and .service files, then run the install commands shown under them.
  4. Check the schedule with systemd-analyze calendar and watch the next run in systemctl list-timers.

Cron fields and their systemd form

CronOnCalendar
0 * * * **-*-* *:00:00
0 0 * * 0Sun *-*-* 00:00:00
0 9 1 * **-*-01 09:00:00
0 0 L * **-*~01 00:00:00
0 9 * * 1#1Mon *-*-01..07 09:00:00

Cron and systemd both use the machine time zone unless you say otherwise. To read a schedule back in plain English, use the cron expression explainer. Shell features such as pipes and redirects are wrapped in /bin/sh -c, and % and $ are escaped for unit files. A CRON_TZ= line above the entry becomes a time zone at the end of OnCalendar, and the user field of an /etc/crontab line becomes User=.

Questions

How do I convert a cron job to a systemd timer?

Write a .service file that holds the command and a .timer file whose OnCalendar= line carries the schedule, then run systemctl enable --now name.timer. A cron line like 30 2 * * 1-5 becomes OnCalendar=Mon..Fri *-*-* 02:30:00.

What does OnCalendar look like for */15 * * * *?

OnCalendar=*-*-* *:00/15:00 runs at minute 0, 15, 30 and 45 of every hour. systemd writes the step as start/interval inside the minute field.

Why does cron run on day of month OR weekday while systemd does not?

When neither day field starts with *, cron runs the job if either one matches, so 0 9 1 * 1 fires on the 1st and on every Monday. systemd requires every part of OnCalendar to match, so the converter writes two OnCalendar lines to keep cron behavior. A field like */2 counts as a star, and then both must match in cron too.

What replaces @reboot?

OnBootSec=1min starts the service one minute after boot. Use a different delay if the job needs the network or a mount to be ready first.

What does Persistent=true do?

systemd remembers when the timer last fired. If the machine was off at the scheduled time, the job runs once when it boots again. Cron skips those runs.

How do I check that my OnCalendar value is right?

Run systemd-analyze calendar "Mon..Fri *-*-* 02:30:00". It prints the normalized form and the next time the timer will elapse.

Need the job to run from outside the server?

A timer only fires while that machine is up and healthy. RunLater calls any URL on a cron schedule or at an exact time, in the time zone you pick, retries failures with backoff and logs every response. Point it at an endpoint or webhook that starts the job, and get an alert email when a run fails.

Starter is $15/month for 250 scheduled requests and 25,000 runs. Cancel before day 14 and you pay nothing.