Run command with systemd periodically

If you wish to run a command periodically with systemd create a service with the following content:

[Unit] Description=Autorun command After=network.target network-online.target [Service] RestartSec=30 Restart=always User=<user> ExecStart=/command/to/be/run [Install] WantedBy=multi-user.target

Edit RestartSec for the time (in seconds) between each run.

Restart service automatically after a pre-defined interval

Therefore add the following line to the system section of the service:

RuntimeMaxSec=180s

It's required that Restart=always otherwise the service will just be interupted but won't restarted! Adjust the runtime-interval by changing the 180s.