One advantage of systemd.timer over cron job is, you can easily get detailed execution log from journalctl -u. Here is a demo of creating a simple task that runs periodically.

Create a timer file minute.timer

1
2
3
4
5
6
7
8
[Unit]
Description=Run a demo.
[Timer]
OnCalendar=minutely
[Install]
WantedBy=timers.target

For more period options for OnCalendar, please visit systemd.time — Time and date specifications.

Create a service file minute.service

1
2
3
4
5
6
[Unit]
Description=Perform action
[Service]
Type=simple
ExecStart=/tmp/helloworld.sh

Don’t forget to create a simple helloworld.sh in /tmp folder.

Launch timer

1
2
sudo systemctl start minute.timer
sudo systemctl status minute.timer

If you want the timer to launch automatically upon OS reboot, run the command below,

1
sudo systemctl enable minute.timer

To check the detailed execution log, run journalctl

1
sudo journalctl -u minute

Reference