To get the system CPU temperature in Celsius in Go, you can use the os/exec
package to run the command sensors
(assuming that this command is available on your system). Then, you can parse the output of the command to extract the CPU temperature.
Here's how you can do it:
main.go884 chars39 lines
Note that this code extracts the temperature of the first CPU core. You can modify the regular expression to extract the temperature of a different core if needed. Also, keep in mind that the output format of the sensors
command may vary depending on your system.
gistlibby LogSnag