Cron Expression to systemd Timer Converter
Free tool to convert a cron expression (minute hour day month weekday) into systemd timer OnCalendar= syntax. Warns about the day-of-month/day-of-week OR-semantics caveat, useful for migrating cron jobs to Docker/Kubernetes environments.
Cron Field to systemd Component Mapping
The 5 fields of a cron expression map to systemd's OnCalendar= syntax as follows.
| Position | Cron field | systemd equivalent |
|---|---|---|
| 1 | Minute | Minute of the time part (MM in HH:MM:SS) |
| 2 | Hour | Hour of the time part (HH in HH:MM:SS) |
| 3 | Day of month | Day of the date part (day in year-month-day) |
| 4 | Month | Month of the date part (month in year-month-day) |
| 5 | Day of week | Weekday prefix (e.g. Mon, Mon..Fri) |
Since cron has no seconds field, the systemd seconds component is always "00". When both day-of-month and month are unrestricted (*), the year-month-day part of systemd can be omitted entirely.
Cron Weekday Number to systemd Weekday Abbreviation
Cron represents weekdays as numbers 0-7, while systemd uses English weekday abbreviations.
| Cron weekday number | systemd weekday abbreviation |
|---|---|
| 0 (7) | Sun |
| 1 | Mon |
| 2 | Tue |
| 3 | Wed |
| 4 | Thu |
| 5 | Fri |
| 6 | Sat |
Common Conversion Examples
| Cron expression | OnCalendar= | Meaning |
|---|---|---|
| * * * * * |
OnCalendar=*-*-* *:*:00
|
Runs every minute (equivalent to cron's "* * * * *"). |
| */15 * * * * |
OnCalendar=*:00/15:00
|
Runs every 15 minutes. |
| 0 9 * * 1-5 |
OnCalendar=Mon..Fri 09:00:00
|
Runs at 9:00 AM on weekdays (Monday through Friday). |
| 0 0 1 * * |
OnCalendar=*-*-01 00:00:00
|
Runs at midnight on the 1st of every month. |
| 0 0 1 1 * |
OnCalendar=*-01-01 00:00:00
|
Runs at midnight on January 1st every year. |
| 0 0 1 * 1 |
OnCalendar=Mon 00:00:00
OnCalendar=*-*-01 00:00:00
|
An example specifying both day-of-month (the 1st) and day-of-week (Monday). In cron this is an OR condition (runs if either matches). A single line such as Mon *-*-01 would be an AND condition (the 1st that is a Monday) and would run only one to three times a year, so the result uses two lines to keep the same meaning. |
A cron expression that restricts both day-of-month and day-of-week (neither starts with an asterisk) changes meaning if written as a single OnCalendar= line, because cron uses OR there while systemd uses AND within one line. Writing two lines in the same .timer unit, one for the weekday and one for the date, makes it run on days that match either, which is exactly what cron does.
Rewriting a cron expression as a systemd timer
Moving a schedule from cron to a systemd timer means translating the five fields of minute, hour, day of month, month and day of week into the OnCalendar= syntax. Enter a cron expression and this tool produces the corresponding OnCalendar=, together with warnings about anything that deserves care.
The most important thing in this translation is how day of month and day of week behave when both are given. Cron reads the two as an OR: 0 0 1 * 1 means "the first of the month or every Monday" and may fire some five times a month. Systemd's OnCalendar=, however, treats the same specification as an AND. It comes to mean "the first and a Monday" and fires only one to three times a year. A mechanical translation therefore changes how often the job runs, and does so silently. This tool detects that combination and splits it into two OnCalendar= lines so the meaning is preserved.
How to convert
- Enter the cron expression Write the five fields — minute, hour, day of month, month, day of week — separated by spaces.
- Review the generated OnCalendar= You are given the corresponding systemd syntax.
- Read the warnings Where day of month and day of week are both given, the change in meaning is pointed out.
-
Transcribe it into a timer unit
Paste it into the
[Timer]section of a.timerfile.
Tips for getting more out of it
- If you restrict both day-of-month and day-of-week, cron reads them as an OR condition. Since systemd treats them as AND within one line, this tool outputs two OnCalendar= lines; a single timer with several lines fires whenever any of them matches.
- Minimal container images, such as the official Debian and Ubuntu Docker images, often ship without a cron daemon (Alpine Linux does include BusyBox crond, but you have to start it yourself). If the host runs systemd, moving the job to a systemd timer is a practical option.
- You can validate the generated OnCalendar line with the "systemd-analyze calendar" command, which also shows the next scheduled run times.
- Unlike a single crontab line, a systemd timer is made of two files: a .timer unit (the schedule) and a .service unit (the actual job to run).
- systemd's repetition syntax (e.g. 00/15) has no end value, so a bounded step such as cron's 10-20/5 is expanded to a list like 10,15,20. A weekday step (*/2) cannot be written as Sun/2 in systemd either, so it is expanded to Sun,Tue,Thu,Sat.
Where it comes in useful
Moving to a container environment
Containers often carry no cron daemon, so schedules have to move to systemd timers or some other arrangement.
Wanting a record of what ran
A systemd timer leaves its trace in journald, which can be followed up afterwards.
Wanting dependencies between jobs
Running only after another unit has started is something cron cannot express.
Taking stock of existing schedules
Converting a set of cron expressions together gives you the occasion to check that the intervals are what you meant.
Scheduler terms
- Cron expression
- The syntax expressing a time by five fields: minute, hour, day of month, month and day of week. Day of month and day of week are read as an OR.
- OnCalendar=
- The key stating the time in a systemd timer. Day of month and day of week are read as an AND.
- Timer unit
- A file with the
.timerextension, which starts the.serviceof the same name. - Persistent=
- The setting that makes a timer catch up after boot if the system was down when it should have fired. It works much as
anacrondoes for cron. - AccuracySec=
- The tolerance on the firing time. A minute of slack applies by default, so state it where the timing must be exact.
- Journald
- Systemd's log collection. The output of a job started by a timer is kept here as well.
Frequently Asked Questions
Side Note — From Cron to systemd Timers
systemd emerged around 2010 as an init system for managing Linux boot processes and has since become the standard on most distributions. Its timer feature provides periodic execution much like cron, but adds capabilities cron never had: dependency resolution, centralized execution logging via journalctl, and configurable retry behavior on failure.
Meanwhile, container environments like Docker and Kubernetes increasingly ship base images without a cron daemon at all, in order to keep image sizes small. When a periodic job needs to run in such environments, the practical options are to rely on an orchestrator-level mechanism such as a Kubernetes CronJob, or to hand it off to systemd timers if the host itself runs systemd.
The OnCalendar= syntax is more expressive than cron's 5 fields — supporting year-level specificity and second-level precision — but that extra expressiveness means some cron expressions (those restricting both day-of-month and day-of-week as an OR condition) change meaning under a naive conversion. This tool surfaces that warning explicitly so migrations don't trip over a pitfall that's easy to miss.