How to Use Systemd Timers

Let’s say you have a script /usr/local/bin/myscript that you want to run every hour. Service File

First, create a service file, and put it wherever it goes on your Linux distribution (on Arch, it is either /etc/systemd/system/ or /usr/lib/systemd/system).

#myscript.service
[Unit]
Description=MyScript

[Service]
Type=simple
ExecStart=/usr/local/bin/myscript

Note that it is important to set the Type variable to be “simple”, not “oneshot”. Using “oneshot” makes it so that the script will be run the first time, and then systemd thinks that you don’t want to run it again, and will turn off the timer we make next. Timer File

Next, create a timer file, and put it also in the same directory as the service file above.

#myscript.timer
[Unit]
Description=Runs myscript every hour

[Timer]
# Time to wait after booting before we run first time
OnBootSec=10min
# Time between running each consecutive time
OnUnitActiveSec=1h
Unit=myscript.service

[Install]
WantedBy=multi-user.target

Enable / Start

Rather than starting / enabling the service file, you use the timer.

# Start timer, as root
systemctl start myscript.timer
# Enable timer to start at boot
systemctl enable myscript.timer
# Timer status
systemctl status myscript.timer
# List timers
systemctl list-timers
# See log
journalctl -u myscript.service [-b(since boot) --since today -f(like tailf -f) ]

source about timers
source about journalctl