Use Systemd Timer Instead of Cron Jobs
Feb 17, 2017
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 | [Unit] |
For more period options for OnCalendar
, please visit systemd.time — Time and date specifications.
Create a service file minute.service
1 | [Unit] |
Don’t forget to create a simple helloworld.sh
in /tmp
folder.
Launch timer
1 | sudo systemctl start 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 |