Systemd - Task Scheduling

Schedule tasks on Linux using systemd timers and services.

Create Timer and Service

Create a Service

  • Create a file /etc/systemd/system/myscript.service

[Unit]
Description="Put a description of the service"

[Service]
Type=simple
ExecStart=/path/to/your/script.sh
User=user_who_runs_the_program
Group=group_who_runs_the_program
  • Type

    • simple

    • exec

    • forking

    • oneshot

    • dbus

    • notify

    • idle

Create a Timer

  • Create a file /etc/systemd/system/myscript.timer

  • Value for OnCalendar is on the systemd.time syntax: *-*-* *:*:*

    • Special keywords: hourly, daily, weekly, monthly, yearly

  • AccuracySec=1min Allow a 1-minute delay to group wakeups.

  • RandomizedDelaySec=30min Add random delay (up to 30 min).

  • Persistent=true Run missed jobs if the system was off.

  • WakeSystem=true Wake up the system to run the job (requires suspend/hibernate support).

Enable & Start the Timer

More information

  • man systemd.timer

  • man systemd.time

Last updated