cancel
Showing results for 
Search instead for 
Did you mean: 
Trevor
Commander Commander
Commander
  • 318 Views

systemd timer

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".

Trevor "Red Hat Evangelist" Chandler
Labels (3)
6 Replies
Blue_bird
Starfighter Starfighter
Starfighter
  • 183 Views

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

Trevor
Commander Commander
Commander
  • 159 Views

Way to go Blue_bird!  Way to go!!!!

Trevor "Red Hat Evangelist" Chandler
0 Kudos
Chetan_Tiwary_
Community Manager
Community Manager
  • 159 Views

@Trevor 

[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 

Trevor
Commander Commander
Commander
  • 156 Views

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 "Red Hat Evangelist" Chandler
Chetan_Tiwary_
Community Manager
Community Manager
  • 152 Views

@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.

Trevor
Commander Commander
Commander
  • 151 Views

Whew!  What a relief

Thanks Chetan for validating my understanding!!!

Trevor "Red Hat Evangelist" Chandler
0 Kudos
Join the discussion
You must log in to join this conversation.