Systemd Timers: The Modern Cron Alternative
Systemd timers have largely replaced cron jobs on modern Linux distributions. They offer significant advantages: journalctl integration for centralized logging, dependency management between services, persistent timers that survive reboots, and resource control via cgroups.
dargslan-systemd-timer is a free Python CLI tool that helps you list, audit, and monitor systemd timers, detect failed timer services, and compare your timer setup with legacy cron jobs.
Install dargslan-systemd-timer
pip install dargslan-systemd-timer
Zero external dependencies. Works on any Linux distribution with systemd.
Timer Report
dargslan-timer report
Shows all active timers with their state, description, and any issues. Also compares systemd timers with existing cron jobs.
List Timers
# Active timers only
dargslan-timer list
# All timers (including inactive)
dargslan-timer list --all
Displays timer units and their associated service units.
Detect Failed Services
dargslan-timer failed
Checks all timer-triggered services for failures. A failed service means the scheduled task did not complete successfully β this requires immediate attention.
Cron Comparison
dargslan-timer cron
Lists current cron entries and compares them with systemd timers. Provides migration recommendations for moving legacy cron jobs to modern systemd timers.
Python API
from dargslan_systemd_timer import TimerManager
tm = TimerManager()
# List all timers
timers = tm.list_timers(all_timers=True)
for t in timers:
print(f"{t['timer']} -> {t['unit']}")
# Timer status details
status = tm.timer_status("apt-daily.timer")
print(f"State: {status['active']}")
print(f"Description: {status['description']}")
print(f"Next trigger: {status['next_trigger']}")
# Find failed services
failed = tm.check_failed()
for f in failed:
print(f"FAILED: {f['timer']} -> {f['unit']}")
# Cron comparison
cron = tm.compare_with_cron()
print(f"Timers: {cron['timers']}, Cron jobs: {cron['cron_entries']}")
print(cron['recommendation'])
Systemd Timer vs Cron
| Feature | Systemd Timer | Cron |
|---|---|---|
| Logging | journalctl integration | Email or redirect |
| Dependencies | After=, Requires= | None |
| Persistence | Persistent=true | Missed runs lost |
| Resource Control | CPUQuota, MemoryMax | None |
| Accuracy | Microsecond | Minute |
| Randomized Delay | RandomizedDelaySec | Manual sleep |
| Failure Handling | OnFailure= unit | None built-in |
Creating a Systemd Timer
Example: Run a backup script daily at 2 AM.
Service Unit (/etc/systemd/system/backup.service)
[Unit]
Description=Daily Backup Script
[Service]
Type=oneshot
ExecStart=/usr/local/bin/backup.sh
User=root
Timer Unit (/etc/systemd/system/backup.timer)
[Unit]
Description=Run backup daily at 2 AM
[Timer]
OnCalendar=*-*-* 02:00:00
Persistent=true
RandomizedDelaySec=300
[Install]
WantedBy=timers.target
Enable and Start
sudo systemctl daemon-reload
sudo systemctl enable --now backup.timer
sudo systemctl list-timers backup.timer
Audit Results
The audit checks for:
- CRITICAL: Failed timer-triggered services
- WARNING: Inactive timers that should be running
- INFO: Cron jobs that could be migrated to timers
Download the Free Cheat Sheet
Get the complete Systemd Timer Cheat Sheet PDF with timer creation templates, CLI commands, and Python API reference.
Master Linux Automation
Explore our Linux administration eBooks covering systemd, automation, and modern sysadmin practices. Check out all 20+ free Python CLI tools at dargslan.com.