systemd_timers
Systemd timers, example
Lets say we want to start /home/heather/screenshot.sh
every day at 23:58, with the parameter 4.
- Create a service file
/etc/systemd/system/HeatherScreenshot.service
:[Unit] Description=HeatherScreenshot [Service] User=heather Type=simple ExecStart=/home/heather/screenshot.sh 4
- Create a timer file
/etc/systemd/system/HeatherScreenshot.timer
:[Unit] Description=Runs HeatherScreenshot [Timer] # DayOfWeek Year-Month-Day Hour:Minute:Second OnCalendar=23:58:00 Unit=HeatherScreenshot.service [Install] WantedBy=multi-user.target
- Test run the static service:
systemctl start HeatherScreenshot.service
- Start and enable the timer:
systemctl daemon-reload # if you modified the files systemctl start HeatherScreenshot.timer systemctl enable HeatherScreenshot.timer
- Show timer status:
systemctl list-timers --all NEXT LEFT LAST PASSED UNIT ACTIVATES Fri 2016-12-30 22:47:15 CET 4h 35min left Thu 2016-12-29 22:47:15 CET 19h ago systemd-tmpfiles-clean.timer systemd-tmpfiles-clean.service Sat 2016-12-31 00:00:00 CET 5h 47min left Fri 2016-12-30 00:00:05 CET 18h ago logrotate.timer logrotate.service Sat 2016-12-31 00:00:00 CET 5h 47min left Fri 2016-12-30 00:00:05 CET 18h ago man-db.timer man-db.service Sat 2016-12-31 00:00:00 CET 5h 47min left Fri 2016-12-30 00:00:05 CET 18h ago shadow.timer shadow.service Sat 2016-12-31 00:59:55 CET 6h left Fri 2016-12-30 12:27:32 CET 5h 44min ago HeatherScreenshot.timer HeatherScreenshot.service 5 timers listed.
- To disable a timer, first stop and than disable it:
systemctl stop HeatherScreenshot.timer systemctl disable HeatherScreenshot.timer
systemd_timers.txt · Last modified: 2021/10/09 15:14 by 127.0.0.1