Linux systemd Timers Guide - ryzendew/Linux-Tips-and-Tricks GitHub Wiki
⏰ 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
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:
.timerfile - Service unit:
.servicefile (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
- systemd Advanced - Advanced systemd
- System Configuration - System setup
- systemd Timers: https://wiki.archlinux.org/title/Systemd/Timers
This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.