Skip to content

Linux systemd Timers Guide

Mattscreative edited this page Dec 5, 2025 · 2 revisions

⏰ Linux systemd Timers Guide

Complete beginner-friendly guide to systemd timers on Linux, covering Arch Linux, CachyOS, and other distributions including creating timers, scheduling tasks, and replacing cron.


Table of Contents

  1. Understanding systemd Timers
  2. Creating Timers
  3. Timer Configuration
  4. Timer Management
  5. Troubleshooting

Understanding systemd Timers

What are systemd Timers?

systemd timers are systemd's replacement for cron.

Advantages:

  • Logging: Integrated with journald
  • Dependencies: Can depend on other units
  • Calendar: Flexible scheduling
  • OnBoot/OnCalendar: Multiple trigger types

Components:

  • Timer unit: .timer file
  • Service unit: .service file (what to run)

Creating Timers

Create Service

Create service file:

# Create service
sudo vim /etc/systemd/system/my-task.service

Add:

[Unit]
Description=My Task

[Service]
Type=oneshot
ExecStart=/usr/bin/my-script.sh

Create Timer

Create timer file:

# Create timer
sudo vim /etc/systemd/system/my-task.timer

Add:

[Unit]
Description=Run My Task

[Timer]
OnCalendar=daily
OnBootSec=15min

[Install]
WantedBy=timers.target

Timer Configuration

Calendar Format

OnCalendar syntax:

OnCalendar=Mon *-*-* 00:00:00  # Every Monday
OnCalendar=*-*-* 02:00:00       # Daily at 2 AM
OnCalendar=*-*-01 00:00:00      # Monthly on 1st
OnCalendar=hourly               # Every hour

Relative Time

Relative timers:

OnBootSec=15min
OnUnitActiveSec=1h
OnStartupSec=10min

Timer Management

Enable Timer

Enable and start:

# Enable timer
sudo systemctl enable my-task.timer

# Start timer
sudo systemctl start my-task.timer

# Check status
systemctl status my-task.timer

List Timers

View timers:

# List all timers
systemctl list-timers

# List active timers
systemctl list-timers --active

Troubleshooting

Timer Not Running

Check status:

# Check timer
systemctl status my-task.timer

# Check service
systemctl status my-task.service

# Check logs
journalctl -u my-task.service

Timer Errors

Check configuration:

# Test timer
systemctl list-timers my-task.timer

# Check service
systemctl cat my-task.service

Summary

This guide covered systemd timers, creating scheduled tasks, and timer management for Arch Linux, CachyOS, and other distributions.


Next Steps


This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.

Clone this wiki locally