Linux β’ Timers & Automation
How to Create a Systemd Timer to Replace Cron Jobs
Systemd timers supersede legacy crontab. They provide unified logging in journalctl, can trigger on relative intervals (`OnBootSec`, `OnUnitActiveSec`) or calendar events (`OnCalendar`), and support randomized delays to prevent thundering herd problems.
/etc/systemd/system/backup-task.service
[Unit]
Description=Database Backup Script
After=network.target
[Service]
Type=oneshot
User=root
WorkingDirectory=/opt/scripts
ExecStart=/opt/scripts/backup.sh
StandardOutput=journal
StandardError=journalCustomize:
User:
WorkingDir:
ExecStart:
Systemctl Lifecycle & Journalctl Monitoring
sudo systemctl daemon-reloadLoad both .service and .timer unitssudo systemctl enable --now backup-task.timerEnable and activate the timer schedulesudo systemctl list-timersList all active timers with next run time and remaining countdownsudo systemctl start backup-task.serviceManually trigger a test execution without waiting for timerLinux & Systemd Production Best Practices
- Enable the `.timer` unit, NOT the `.service` unit! The timer automatically activates the service when triggered.
- `Persistent=true` ensures that if the server was powered off when the timer was scheduled to fire, it will execute immediately on the next boot.
Frequently Asked Questions About Systemd Timer (Cron Alternative)
Frequently Asked Questions
Frequently Asked Questions
Everything you need to know regarding specifications, syntax, and security best practices.
Timers log every execution cleanly to journalctl, handle missed runs during server downtime (`Persistent=true`), and support randomized delays to avoid server load spikes.
Related Linux & Systemd Services
View All ServicesWeb Apps & APIs
How to Create a Systemd Service for Node.js (Express, NestJS, Next.js)
node-app.serviceGuide β
Web Apps & APIs
How to Create a Systemd Service for Python (FastAPI, Flask, Gunicorn, Uvicorn)
python-app.serviceGuide β
Web Apps & APIs
How to Create a Systemd Service for Go (Golang) Compiled Binary
go-service.serviceGuide β
Background Workers & Daemons
How to Run Background Workers (Celery, BullMQ, Sidekiq) with Systemd
queue-worker.serviceGuide β
Infrastructure & Tunnels
How to Run Docker Compose as a Systemd Service
docker-compose-app.serviceGuide β
Infrastructure & Tunnels
How to Keep Reverse SSH Tunnel Persistent with Autossh & Systemd
reverse-tunnel.serviceGuide β