Skip to content

Instantly share code, notes, and snippets.

@ineentho
Last active June 14, 2020 16:54
Show Gist options
  • Save ineentho/d69874bfeea6b290925842af77de0fa9 to your computer and use it in GitHub Desktop.
Save ineentho/d69874bfeea6b290925842af77de0fa9 to your computer and use it in GitHub Desktop.
Using systemd services as a cron replacement

Create service file:

sudo EDITOR=nvim systemctl edit --force --full my-cron-service.service

Create timer file:

sudo EDITOR=nvim systemctl edit --force --full my-cron-service.timer

Enable the newly created timer:

sudo systemctl enable --now my-cron-service.timer
[Unit]
Description=Example service
[Service]
Type=oneshot
ExecStart=echo example service
[Unit]
Description=Example service
[Timer]
OnCalendar=*-*-* 04:00:00
RandomizedDelaySec=3600
Persistent=true
[Install]
WantedBy=timers.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment