mkunit timer

Create a systemd timer unit (cron replacement).

mkunit timer <name> [flags]

Description

The timer command creates a .timer unit file for scheduling services to run at specific times or intervals. Timers are more flexible and reliable than cron, supporting features like persistent timers, randomized delays, and calendar expressions.

Arguments

Argument Description
<name> Name of the timer (without .timer extension)

Flags

Flag Description Default
--unit <name> Service unit to trigger (defaults to same name as timer) <name>.service
--on-calendar <expr> Calendar expression (e.g., "daily", "*:0/15")
--on-boot <seconds> Run N seconds after boot
--on-startup <seconds> Run N seconds after service manager start
--on-unit-active <seconds> Run N seconds after unit was last activated
--on-unit-inactive <seconds> Run N seconds after unit became inactive
--persistent Run immediately if last run was missed false
--randomized-delay <seconds> Add random delay (0 to N seconds)
--accuracy <seconds> Timer accuracy/coalescing window 60
--description <text> Human-readable description Auto-generated
--system Create a system timer (requires sudo) false
--install Install the unit file after creation false
--start Start the timer after installation false
--enable Enable the timer to start on boot false
--dry-run Print unit file without writing false

Calendar Expressions

Systemd uses calendar expressions for scheduling. Here are common patterns:

Expression Description
minutelyEvery minute
hourlyEvery hour at :00
dailyEvery day at 00:00
weeklyEvery Monday at 00:00
monthlyFirst of every month at 00:00
yearlyJanuary 1st at 00:00
*:0/15Every 15 minutes
*:0/5Every 5 minutes
Mon..Fri 09:00Weekdays at 9am
Sat,Sun 10:00Weekends at 10am
*-*-01 00:00First of every month at midnight
Sun *-*-* 03:00:00Every Sunday at 3am
*-01-01 00:00:00New Year's Day at midnight
Tip

Use systemd-analyze calendar "expression" to test calendar expressions and see when they would trigger.

Examples

Daily backup at midnight

mkunit timer backup --on-calendar "daily" --unit backup.service

Every 15 minutes

mkunit timer sync --on-calendar "*:0/15" --install --start

5 minutes after boot

mkunit timer startup-task --on-boot 300 --install --enable

Weekly on Sunday at 3am

mkunit timer weekly-cleanup --on-calendar "Sun *-*-* 03:00:00"

Weekdays at 9am

mkunit timer workday-report --on-calendar "Mon..Fri 09:00" --install

Persistent timer (catches up if missed)

mkunit timer important-job --on-calendar "daily" --persistent --install

With randomized delay (for load distribution)

mkunit timer distributed-task \
  --on-calendar "hourly" \
  --randomized-delay 300 \
  --install

Run every 30 minutes after last run

mkunit timer recurring-task --on-unit-active 1800 --install --start

See Also