Need help with a systemd timer

I’m trying to get a script to run every 3 seconds to grab all my sensor data and parse it into files so I can use it in my conky.
I’ve made a systemd service to run the script, and a timer to run the service 30 secs after each boot, and every 3 seconds after (supposedly), but for some reason it only runs on the 42nd or 43rd second of every minute, plus a couple random times thrown in.

After almost 10 minutes it’s only run 20 times. It should be running 20 times per minute. What the actual fuck am I doing wrong? I don’t get it.

Summary
[user1@COMPUTER0 ~]$ sudo systemctl status store-temporary-sensor-data.timer
[sudo] password for user1: 
● store-temporary-sensor-data.timer - Timer for refreshing stored sensor data
   Loaded: loaded (/etc/systemd/system/store-temporary-sensor-data.timer; disabled; vendor preset: disabled)
   Active: active (running) since Wed 2020-02-26 05:02:43 AST; 9min ago
  Trigger: n/a

Feb 26 05:02:43 COMPUTER0 systemd[1]: Started Timer for refreshing stored sensor data.
[user1@COMPUTER0 ~]$ cat /etc/systemd/system/store-temporary-sensor-data.timer
[Unit]
Description=Timer for refreshing stored sensor data

[Timer]
OnBootSec=30sec
OnUnitActiveSec=3sec

[Install]
WantedBy=timers.target
[user1@COMPUTER0 ~]$ cat /etc/systemd/system/store-temporary-sensor-data.service 
[Unit]
Description=Get and store temporary sensor values

[Service]
Type=simple
ExecStart=/bin/bash /home/user1/.sensordata.sh
RemainAfterExit=false

[Install]
WantedBy=multi-user.target
[user1@COMPUTER0 ~]$ journalctl -u store-temporary-sensor-data.service
-- Logs begin at Tue 2020-02-25 09:02:28 AST, end at Wed 2020-02-26 05:12:13 AST. --
Feb 26 05:02:43 COMPUTER0 systemd[1]: Started Get and store temporary sensor values.
Feb 26 05:02:44 COMPUTER0 systemd[1]: store-temporary-sensor-data.service: Succeeded.
Feb 26 05:02:59 COMPUTER0 systemd[1]: Started Get and store temporary sensor values.
Feb 26 05:03:00 COMPUTER0 systemd[1]: store-temporary-sensor-data.service: Succeeded.
Feb 26 05:03:42 COMPUTER0 systemd[1]: Started Get and store temporary sensor values.
Feb 26 05:03:43 COMPUTER0 systemd[1]: store-temporary-sensor-data.service: Succeeded.
Feb 26 05:04:30 COMPUTER0 systemd[1]: Started Get and store temporary sensor values.
Feb 26 05:04:30 COMPUTER0 systemd[1]: store-temporary-sensor-data.service: Succeeded.
Feb 26 05:04:42 COMPUTER0 systemd[1]: Started Get and store temporary sensor values.
Feb 26 05:04:43 COMPUTER0 systemd[1]: store-temporary-sensor-data.service: Succeeded.
Feb 26 05:05:28 COMPUTER0 systemd[1]: Started Get and store temporary sensor values.
Feb 26 05:05:28 COMPUTER0 systemd[1]: store-temporary-sensor-data.service: Succeeded.
Feb 26 05:05:42 COMPUTER0 systemd[1]: Started Get and store temporary sensor values.
Feb 26 05:05:43 COMPUTER0 systemd[1]: store-temporary-sensor-data.service: Succeeded.
Feb 26 05:06:00 COMPUTER0 systemd[1]: Started Get and store temporary sensor values.
Feb 26 05:06:01 COMPUTER0 systemd[1]: store-temporary-sensor-data.service: Succeeded.
Feb 26 05:06:42 COMPUTER0 systemd[1]: Started Get and store temporary sensor values.
Feb 26 05:06:43 COMPUTER0 systemd[1]: store-temporary-sensor-data.service: Succeeded.
Feb 26 05:07:31 COMPUTER0 systemd[1]: Started Get and store temporary sensor values.
Feb 26 05:07:32 COMPUTER0 systemd[1]: store-temporary-sensor-data.service: Succeeded.
Feb 26 05:07:42 COMPUTER0 systemd[1]: Started Get and store temporary sensor values.
Feb 26 05:07:43 COMPUTER0 systemd[1]: store-temporary-sensor-data.service: Succeeded.
Feb 26 05:08:42 COMPUTER0 systemd[1]: Started Get and store temporary sensor values.
Feb 26 05:08:43 COMPUTER0 systemd[1]: store-temporary-sensor-data.service: Succeeded.
Feb 26 05:09:00 COMPUTER0 systemd[1]: Started Get and store temporary sensor values.
Feb 26 05:09:01 COMPUTER0 systemd[1]: store-temporary-sensor-data.service: Succeeded.
Feb 26 05:09:42 COMPUTER0 systemd[1]: Started Get and store temporary sensor values.
Feb 26 05:09:43 COMPUTER0 systemd[1]: store-temporary-sensor-data.service: Succeeded.
Feb 26 05:10:30 COMPUTER0 systemd[1]: Started Get and store temporary sensor values.
Feb 26 05:10:31 COMPUTER0 systemd[1]: store-temporary-sensor-data.service: Succeeded.
Feb 26 05:10:42 COMPUTER0 systemd[1]: Started Get and store temporary sensor values.
Feb 26 05:10:43 COMPUTER0 systemd[1]: store-temporary-sensor-data.service: Succeeded.
Feb 26 05:11:42 COMPUTER0 systemd[1]: Started Get and store temporary sensor values.
Feb 26 05:11:43 COMPUTER0 systemd[1]: store-temporary-sensor-data.service: Succeeded.
Feb 26 05:11:57 COMPUTER0 systemd[1]: Started Get and store temporary sensor values.
Feb 26 05:11:58 COMPUTER0 systemd[1]: store-temporary-sensor-data.service: Succeeded.
Feb 26 05:12:01 COMPUTER0 systemd[1]: Started Get and store temporary sensor values.
Feb 26 05:12:01 COMPUTER0 systemd[1]: store-temporary-sensor-data.service: Succeeded.
Feb 26 05:12:05 COMPUTER0 systemd[1]: Started Get and store temporary sensor values.
Feb 26 05:12:05 COMPUTER0 systemd[1]: store-temporary-sensor-data.service: Succeeded.
[user1@COMPUTER0 ~]$ 

i’v read your post between 2 meeting, so might be completly off topic.
i’ve seen this in the doc
AccuracySec=

Specify the accuracy the timer shall elapse with. Defaults to 1min. The timer is scheduled to elapse within a time window starting with the time specified in OnCalendar= , OnActiveSec= , OnBootSec= , OnStartupSec= , OnUnitActiveSec= or OnUnitInactiveSec= and ending the time configured with AccuracySec= later. Within this time window, the expiry time will be placed at a host-specific, randomized, but stable position that is synchronized between all local timer units. This is done in order to optimize power consumption to suppress unnecessary CPU wake-ups. To get best accuracy, set this option to 1us. Note that the timer is still subject to the timer slack configured via systemd-system.conf(5)'s TimerSlackNSec= setting. See prctl(2) for details. To optimize power consumption, make sure to set this value as high as possible and as low as necessary.

Note that this setting is primarily a power saving option that allows coalescing CPU wake-ups. It should not be confused with RandomizedDelaySec= (see below) which adds a random value to the time the timer shall elapse next and whose purpose is the opposite: to stretch elapsing of timer events over a longer period to reduce workload spikes. For further details and explanations and how both settings play together, see below.

1 Like

Thank you so much! Apparently forgot to RTFM. I read that page before I made my timer too but must have glossed over that part. DERP! :crazy_face:

2 Likes

Silly question why not just uses the exec command do and grep and cut what you need?? You can set the intervals that the command runs.

I was trying to take some load off the cpu. It was calling sensors a lot per interval, and if I call sensors manually it takes a second or two to complete. I figured calling it 5 times every 2 or 3 seconds was bogging things down. I was actually aiming to get my refresh interval down to 1 second, but that didn’t work out, because systemd complains if the timer runs more than once every ~2 seconds anyway.

Could also call a script at boot that just runs your function, sleeps 3 seconds, then runs it again.
Inside a while loop

You can set the interval so like my drive temps, I use 30 seconds because the drive temps fluctuate, vs CPU temp.