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.

# nano -w /etc/systemd/system/myscript.timer

with the following content:

[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.

# systemctl start myscript.timer

and enable it with each boot:

# systemctl enable myscript.timer

Running Multiple Scripts on the Same Timer

Now let’s say there are a bunch of scripts you want to run, all at the same time.

In this case, you will want make a couple changes on the above formula.

service files

Create the service files to run your scripts as showed previously,

but include the following section at the end of each service file:

[Install]
WantedBy=mytimer.target

If there is any ordering dependency in your service files, be sure you specify it with

the After=something.service and/or Before=whatever.service parameters within the

Description section.

timer file

You only need a single timer file. Create mytimer.timer, as outlined above.