You are not logged in.

#1 2025-11-24 02:00:32

samdavid6
Member
Registered: 2008-09-18
Posts: 31

[solved] How to persistently read sensors and radeontop data

So I am doing a conky project. I had a bunch of commands such as this to read values

{execi 1 sensors | grep "fan1" | cut -c 15-17}

or

{execi 1 /bin/radeontop -b 3 -d- -l1 | grep "sclk" | cut -c 10-15}

One time for fan speed, one time for gpu frequency... whatever.

I realised that I was having multiple instances of radeontop or sensors running every second, so I thought I would preface my conky commands with

#Save sensor data to /tmp
${execi 1 /bin/sensors > /tmp/sensordata}
${execi 1 /bin/sensors amdgpu-pci-0300 > /tmp/gpusensor}
${execi 999999 /usr/bin/hwinfo --gfxcard > /tmp/hwinfodata}
${execi 5 /bin/radeontop -b 3 -d- -l1 > /tmp/radeontopdata} 

This way I figured, it would run once every second (or every 5 seconds for radeontop) and then save the file to /tmp where I could then run cat to pull whatever info I wanted.

Problem is, is that the file keeps getting overwritten every second, like it is supposed to, but half the time, when my cat command goes to look for the value, the file is either in the process of being written, or so it doesnt return anything.

Is there a different command that I can use to keep sensors, or radeontop running just once, and somehow being able to pull the information out (not every second, but just in a persistent state, if that makes sense?)

I was looking at options like stdout, or pipe or something..

I could also consider looking at the files that sensor goes to find the information and cat those files directly, but this would be muuuuuuuch easier.

Thank you so much for your help, I'm so comfortable with Linux these days, I might even start to move away from "Newbie Corner"

Last edited by samdavid6 (2025-11-24 20:48:02)

Offline

#2 2025-11-24 02:13:39

iburnwindows
Member
Registered: 2025-11-23
Posts: 5

Re: [solved] How to persistently read sensors and radeontop data

You can avoid spawning multiple sensors or radeontop processes by running them in the background and writing their output to a file. For example, have a small script that updates /tmp/sensordata every second (using atomic writes like sensors > /tmp/sensordata.tmp && mv ...) and a similar one for radeontop. Then let Conky just read those files.

On Arch, using systemd to run these scripts as persistent services works well—it keeps one instance running, avoids race conditions, and keeps your Conky config simple.

Offline

#3 2025-11-24 02:18:39

samdavid6
Member
Registered: 2008-09-18
Posts: 31

Re: [solved] How to persistently read sensors and radeontop data

 sensors > /tmp/sensordata.tmp && mv 

Isn't that what I'm doing?  I could shift this over to a systems file instead but would it somehow change the file being written to make it more available to cat in the file?

Right now half the time my cat command is going to read the file, it's not available.  Either being written, updated or something

Offline

#4 2025-11-24 20:47:32

samdavid6
Member
Registered: 2008-09-18
Posts: 31

Re: [solved] How to persistently read sensors and radeontop data

I understand now.  I will try this out.

On a side note, I also found the sponge command that does the same thing, but I had to install moreutils to get it.

{execi 1 /bin/sensors | sponge /tmp/sensordata}

Offline

Board footer

Powered by FluxBB