1. Prepare the timing script
If it is a Bash script, the first line needs to specify the interpreter.
|
|
2. add timer
|
|
Various parameters can be used in [Timer]
to control the execution period of the timed task.
- OnActiveSec, how much time to start executing the task after the timer takes effect
- OnBootSec, how much time to start the task after the system is started
- OnStartupSec, how long after the Systemd process starts, how long after the task starts
- OnUnitActiveSec, how much time to wait after the last execution of the unit to execute again
- OnUnitInactiveSec, how much time since the timer was last closed, executed again
- OnCalendar, based on absolute time, not relative time execution
- AccuracySec, if the task must be postponed for various reasons, the maximum number of seconds to postpone, the default is 60 seconds
3. add service
|
|
4. Manage timed tasks
-
Loading configuration
1
systemctl daemon-reload
-
Start a timed task
1
systemctl start quick-clear.timer
-
View Task Status
1
systemctl status quick-clear.timer
-
Boot up
1
systemctl enable quick-clear.timer
-
View Task Log
-
View All Timed Tasks
1 2 3 4 5 6 7 8 9 10 11 12 13 14
systemctl list-timers NEXT LEFT LAST PASSED UNIT ACTIVATES Thu 2022-05-26 15:54:35 CST 1h 23min left Thu 2022-05-26 03:42:34 CST 10h ago ua-messaging.timer ua-messaging.service Thu 2022-05-26 17:58:00 CST 3h 27min left Wed 2022-05-25 17:58:00 CST 20h ago systemd-tmpfiles-clean.timer systemd-tmpfiles-clean.service Thu 2022-05-26 19:56:45 CST 5h 26min left Thu 2022-05-26 11:45:53 CST 2h 44min ago fwupd-refresh.timer fwupd-refresh.service Fri 2022-05-27 00:00:00 CST 9h left Thu 2022-05-26 00:00:00 CST 14h ago logrotate.timer logrotate.service Fri 2022-05-27 00:00:00 CST 9h left Thu 2022-05-26 00:00:00 CST 14h ago man-db.timer man-db.service Fri 2022-05-27 00:00:37 CST 9h left Thu 2022-05-26 14:30:07 CST 35s ago motd-news.timer motd-news.service Fri 2022-05-27 04:38:51 CST 14h left Thu 2022-05-26 14:29:47 CST 55s ago apt-daily.timer apt-daily.service Fri 2022-05-27 06:09:35 CST 15h left Thu 2022-05-26 06:37:25 CST 7h ago apt-daily-upgrade.timer apt-daily-upgrade.service Sun 2022-05-29 03:10:09 CST 2 days left Sun 2022-05-22 03:10:55 CST 4 days ago e2scrub_all.timer e2scrub_all.service Mon 2022-05-30 00:00:00 CST 3 days left Mon 2022-05-23 00:00:00 CST 3 days ago fstrim.timer fstrim.service Wed 2022-06-01 18:53:47 CST 6 days left n/a n/a quick-clear.timer quick-clear.service