You can use the sensors
command, which is available in most modern Linux distributions, to get the system CPU temperature. You can execute the command using the backticks operator in Ruby and parse the output to extract the temperature value.
Here's a code snippet that demonstrates how to get the CPU temperature in Celsius:
main.rb366 chars5 lines
Note that the sensors
command might require administrative privileges to run, so make sure to run your Ruby script with the appropriate permissions, or add your user to the sudoers
group.
gistlibby LogSnag