cron ↔ systemd timer

Convert cron to a systemd timer, and back.

Turn a crontab line into OnCalendar= plus ready-to-install .timer and .service files, or turn an OnCalendar= expression into cron. Both directions use ports of the real parsers (systemd's calendarspec.c and Debian's cron), and every conversion is checked by running both schedules side by side.

How systemd timer (OnCalendar=) differs from Linux cron. Day of week: Names only: Mon..Sun. Time zone: Local time, or a zone at the end (Europe/Berlin, UTC). Compare systemd timer (OnCalendar=) with Linux cron, side by side →
Read this before you switch

Where cron and systemd timers behave differently.

Featurecronsystemd timer
Day-of-month and weekday both setRuns when either matches (unless one field starts with *)Runs only when both match. To copy cron, use two OnCalendar= lines: a timer may have several.
Exact start timeAt the start of the minuteAnywhere in a 1-minute window by default (AccuracySec=1min, to save power). Set AccuracySec=1s to start on time.
Machine was off at the scheduled timeThe run is skipped (unless you use anacron)Skipped too, unless Persistent=true, which runs it once as soon as the timer starts again
CommandA shell line, run by /bin/sh; % starts standard inputExecStart= is not a shell: no pipes or >. Wrap it in /bin/sh -c '…'. Write %% for %, $$ for $, and \\ for \.
PATH/usr/bin:/bin on Debian/Ubuntu (more on Fedora/Arch)/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin for system units
Working directoryThe user's home directory/ for system units unless you set WorkingDirectory=
OutputMailed (MAILTO), or lost if no mail serverSaved in the journal: journalctl -u name.service
Overlapping runsA new copy starts even if the last one is still runningNever: a timer can't start a service that is still running
Daylight saving timeA fixed-time job in the skipped hour runs right after the change; jobs with * in the minute or hour field run in both passes of the repeated hourA skipped time is skipped; a repeated time runs once. Check a schedule with the DST checker.
Seconds and yearsNot possiblePossible (*:*:0/10, 2027-*-*)

systemd's / repetition can skip runs

In systemd, *:0/45 means "minute 0, then every 45 minutes". When the next value overflows into the next hour or day, systemd only resets the field directly below the one that changed, so it lands on 00:30 and continues from there. The result: *:0/45 never fires at 00:00 (it runs 23:45, 00:45, 01:00, 01:45…), and *-*-* 0/10:00 skips midnight on the first day of each month. We confirmed this with systemd-analyze calendar on systemd 255, and the same reset logic is in systemd 256-258 and the current main branch. Cron's */45 doesn't do this. When converting from cron, this tool writes plain lists (00,45) whenever / could skip a run; when converting to cron, it warns you which runs systemd skips.

How the conversion is checked

The OnCalendar parser, normaliser and next-run search here are a port of systemd 255's calendarspec.c. We fed 2,961 expressions, the examples from the systemd.time manual, edge cases and 2,900 random ones, to both the port and systemd-analyze calendar. Valid/invalid, the normalized form and the next 12 run times matched on all of them. Then we converted 1,512 cron expressions to OnCalendar and 518 OnCalendar expressions to cron, and compared the next 40 runs of each pair, as computed by systemd-analyze and by a port of Debian's cron parser: 0 differences. In the browser, every conversion is checked again over its next 400 runs before it is shown.

Sources: systemd v255 calendarspec.c and the manuals systemd.time(7), systemd.timer(5), systemd.service(5), systemd.exec(5); Debian crontab(5). Related: crontab checker, common cron expressions.

Common questions

Cron to systemd timer FAQs.

Create two files: name.service with Type=oneshot and ExecStart= your command, and name.timer with OnCalendar= the schedule and WantedBy=timers.target. Then run systemctl daemon-reload and systemctl enable --now name.timer. The converter above writes both files for you.

*:0/5, which systemd normalizes to *-*-* *:00/5:00. Steps that divide the hour evenly (2, 3, 4, 5, 6, 10, 12, 15, 20, 30) are safe; others such as 45 can skip runs in systemd, so use an explicit list like *:00,45.

AccuracySec= defaults to one minute: systemd picks a stable point inside that window to bundle wake-ups. Add AccuracySec=1s to the [Timer] section to start on time.

Yes, and more easily than cron: Mon *-*-01..07 09:00 runs only on days that are both a Monday and between the 1st and 7th. Cron can't say that directly because it runs when either day field matches.

systemctl list-timers --all shows every timer with its next and last run. systemd-analyze calendar --iterations=5 'expression' tests an expression without creating a timer.