You are not logged in.
Pages: 1
hi
struggling a bit with what supposed to be a trivial routine :)
a timer should run timer_test.sh each second, in fact the interval doesn't matter.
The issue here that it fires up only one time,
either when I start or restart service, successful execution is logged as well as script does its job.
However, I'd like it to run indefinitely.
#cd /etc/systemd/system/
#ls timer*
timer_test.service timer_test.timer#cat timer_test.service
[Unit]
Description=Timer Testing
[Service]
Type=oneshot
ExecStart=/bin/bash /usr/local/bin/timer_test.sh#cat timer_test.timer
[Unit]
Description=Timer Testing
[Timer]
OnCalendar=*-*-* *:*:0/1
Persistent=true
Unit=timer_test.service
#systemctl status timer_test.service
● timer_test.service - Timer Testing
Loaded: loaded (/etc/systemd/system/timer_test.service; enabled; vendor preset: disabled)
Active: inactive (dead) since Sun 2020-06-14 06:52:47; 32min ago
Process: 521 ExecStart=/bin/bash /usr/local/bin/timer_test.sh (code=exited, status=0/SUCCESS)
Main PID: 521 (code=exited, status=0/SUCCESS)
Jun 14 06:52:47 abc systemd[1]: Starting Timer Testing...
Jun 14 06:52:47 abc bash[523]: Sun 14 Jun 2020 06:52:47 AM
Jun 14 06:52:47 abc systemd[1]: timer_test.service: Succeeded.
Jun 14 06:52:47 abc systemd[1]: Finished Timer Testing.One more thing
sudo systemctl list-timers --alldoesn't list my timer, as the docs say.
Last edited by freebench (2020-06-14 23:09:03)
Offline
One more thing
sudo systemctl list-timers --alldoesn't list my timer, as the docs say.
Have you started it with systemctl start or something?
Your timer unit is lacking an [Install] section. Without one you'll need to manually start the timer to activate it. You might want a section like:
[Install]
WantedBy=timers.targetso that you can enable it to start automatically. I think if you start the timer unit as is it should work.
Offline
Have you started it with systemctl start or something?
Yes. Right after the it's enabled.
After each corrections done to the files
This is executed
sudo systemctl daemon-reloadFollowing service restart.
You might want a section like:
[Install] WantedBy=timers.target
Added. Result is the same.
Offline
How about adding
[Install]
WantedBy=multi-user.targetto timer-test.service?
Offline
$ systemctl --user cat caching-arch-pkgs-name.timer
# /home/a/.config/systemd/user/caching-arch-pkgs-name.timer
[Unit]
Description=Caching all arch pkgs name from repo and aur
[Timer]
OnStartupSec=1s
OnUnitInactiveSec=1h
[Install]
WantedBy=timers.target
$ systemctl --user cat caching-arch-pkgs-name.service
# /home/a/.config/systemd/user/caching-arch-pkgs-name.service
[Unit]
Description=Caching all arch pkgs name from repo and aur
[Service]
Type=oneshot
ExecStart=/usr/bin/sh -c '/usr/bin/yay -Slq > /home/a/.cache/all-pkgs-name.txt'
SyslogIdentifier=caching-arch-pkgs-nameNot exact answer. But my timer setup is usually,
[Timer]
OnStartupSec=1s <-- required for after reboot
OnUnitInactiveSec=1h <-- this is interval Don't forget,
`systemctl --user enable xxxx.timer` or,
`systemctl enable xxx.timer`.
YCH
Offline
Not exact answer. But my timer setup is usually,
Yep, that's it, thanks
I think, reading the docs is the most valuable skill :D
# /etc/systemd/system/timer_test.timer
[Unit]
Description=Timer Testing
[Timer]
#OnCalendar=*-*-* *:*:0/1
#Persistent=true
#Unit=timer_test.service
OnStartupSec=1s
OnUnitInactiveSec=1s
AccuracySec=1us
[Install]
WantedBy=multi-user.target However firing up isn't accurate, there is 6 seconds gap each 5 seconds ...
Without AccuracySec=, timer fires up randomly, 7, 10,15, 9 sec etc
The script doesn't do anything special, should fit into 1 second
$ cat /usr/local/bin/timer_test.sh
date | tee -a /home/user/timer_lastJun 15 00:53:05 abc timer_test[27524]: Mon 15 Jun 2020 12:53:05 AM
Jun 15 00:53:06 abc timer_test[27527]: Mon 15 Jun 2020 12:53:06 AM
Jun 15 00:53:07 abc timer_test[27530]: Mon 15 Jun 2020 12:53:07 AM
Jun 15 00:53:08 abc timer_test[27533]: Mon 15 Jun 2020 12:53:08 AM
Jun 15 00:53:09 abc timer_test[27536]: Mon 15 Jun 2020 12:53:09 AM
Jun 15 00:53:15 abc timer_test[27543]: Mon 15 Jun 2020 12:53:15 AM
Jun 15 00:53:16 abc timer_test[27546]: Mon 15 Jun 2020 12:53:16 AM
Jun 15 00:53:17 abc timer_test[27549]: Mon 15 Jun 2020 12:53:17 AM
Jun 15 00:53:18 abc timer_test[27552]: Mon 15 Jun 2020 12:53:18 AM
Jun 15 00:53:19 abc timer_test[27555]: Mon 15 Jun 2020 12:53:19 AM
Jun 15 00:53:25 abc timer_test[27568]: Mon 15 Jun 2020 12:53:25 AM
Jun 15 00:53:26 abc timer_test[27571]: Mon 15 Jun 2020 12:53:26 AM
Jun 15 00:53:27 abc timer_test[27574]: Mon 15 Jun 2020 12:53:27 AM
Jun 15 00:53:28 abc timer_test[27577]: Mon 15 Jun 2020 12:53:28 AM
Jun 15 00:53:29 abc timer_test[27580]: Mon 15 Jun 2020 12:53:29 AM
Jun 15 00:53:35 abc timer_test[27583]: Mon 15 Jun 2020 12:53:35 AM
Jun 15 00:53:36 abc timer_test[27586]: Mon 15 Jun 2020 12:53:36 AM
Jun 15 00:53:37 abc timer_test[27589]: Mon 15 Jun 2020 12:53:37 AM
Jun 15 00:53:38 abc timer_test[27592]: Mon 15 Jun 2020 12:53:38 AM
Jun 15 00:53:39 abc timer_test[27596]: Mon 15 Jun 2020 12:53:39 AM
Jun 15 00:53:45 abc timer_test[27599]: Mon 15 Jun 2020 12:53:45 AM
Jun 15 00:53:46 abc timer_test[27602]: Mon 15 Jun 2020 12:53:46 AM
Jun 15 00:53:47 abc timer_test[27605]: Mon 15 Jun 2020 12:53:47 AMOffline
However firing up isn't accurate, there is 6 seconds gap each 5 seconds
[...]
The script doesn't do anything special, should fit into 1 second
Well I'm very late, but if you haven't corrected it yet sounds like it is accurate, but you have specified the interval as OnUnit*Inactive*Sec.
There are many different ways to specify an interval. See systemd.timer(5) man page for the details. InactiveSec is the delay between _deactivation_ and the following start. So your unit starts, the script runs for <1 sec, the unit deactivates, _then_ it waits 5 seconds. Maybe you wanted OnActiveSec? Also your previous example has OnStartupSec _and_ OnUnitInactiveSec. Don't use multiple timer declarations unless you really mean it, again details in systemd.timer(5).
Offline
Pages: 1