I have a shell script named "doit", that I want to have run, each time
my Linux system boots. I want this shell script to run/launch 5 minutes
after the system starts. I want to use a systemd timer to make this happen.
My systemd timer unit file is very simple:
[Unit]
Description=My Timer Description
[Timer]
Persistent=true
[Install]
WantedBy=timers.target
As you can see, I've got 3 simple sections in the timer unit file.
The key piece that I need help with is the directive, that will ensure
my shell script will be launched 5 minutes after the Linux system
boots. I know the directive goes in the "timer" section of the unit file.
I just don't know what the construct (i.e. syntax) looks like. What should
my directive look like?
I just need that one thing - I don't need any assistance with the
service unit file that is going to launch my shell script named "doit".
OnBootSec=5min will cause systemd to trigger the service 5 minutes after the system boots.
[Unit]
Description=My Timer Description
[Timer]
OnBootSec=5min
Persistent=true
[Install]
WantedBy=timers.target
Thanks
Way to go Blue_bird! Way to go!!!!
[Unit] Description= run doit script 5 minutes post boot [Timer] OnBootSec=5min Persistent=true Unit=doit.service [Install] WantedBy=timers.target
https://www.freedesktop.org/software/systemd/man/latest/systemd.timer.html
https://documentation.suse.com/smart/systems-management/html/systemd-working-with-timers/index.html
Chetan
I'm glad you included the line
Unit=doit.service
That prompts the following question: Is that line required, or does systemd automatically look to execute a service unit file with the same prefix in its name - in this case, "doit"?
My limited understanding is that in the case of this scenario, it would not be required.
It certainly is a great practice to be explicit when configuring things. Surely, no one will question what the timer is going to launch, with the Unit directive included in the timer unit file.
@Trevor you are roight!
The Unit= directive in a .timer file is optional if the corresponding .service file shares the same base name as the timer."
This reflects the fact that systemd automatically links a timer to a service unit of the same name unless otherwise specified.
Whew! What a relief
Thanks Chetan for validating my understanding!!!
Red Hat
Learning Community
A collaborative learning environment, enabling open source skill development.