Is it possible to read the CPU temperature in a terminal?
ilg-ul opened this issue · 4 comments
I have a functional 10.14 on a headless NUC8i7BEH, and I use it quite successfully for long builds. Thank you!
I'm interested in a cli command to read the cpu temperature (and possibly the fan rpm).
Do you know of such a command that is functional in the current configuration?
This is way beyond the scope of this repo. There are probably many ways to get the cpu temp, not sure if you can read the fan speeds at all. But you can use something like the powermetrics
command or iStats and see what kind of info you can get.
$ sudo xcode-select --install
$ sudo gem install iStats
Building native extensions. This could take a while...
Successfully installed iStats-1.6.2
Parsing documentation for iStats-1.6.2
Installing ri documentation for iStats-1.6.2
Done installing documentation for iStats after 0 seconds
1 gem installed
$ istats
--- CPU Stats ---
CPU temp: 47.0°C ▁▂▃▅▆▇
--- Fan Stats ---
Total fans in system: 1
Fan 0 speed: 0 RPM ▁▂▃▅▆▇
--- Battery Stats ---
No battery on system
Might be most useful, I run most of my NUCs fanless so I dunno if you can get the fan speed. If not then you will need to check with VirtualSMC
documentation, it likely needs some plugin to get those speeds, if possible at all. But CPU temp surely works.
Thank you for your reply.
Building the ruby gem fails with:
make: *** No rule to make target `/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin21/ruby/config.h', needed by `smc.o'. Stop.
Getting the fan rpm is not so important.
If you confirmed that reading the temperature is functional on your machine, I'll try to take a look at the ruby code, perhaps I can get a clue how to do it in a shell script.
If you have Xcode installed you need to switch to use Xcode and not the command line tools. I assumed you had no Xcode installed. Else something went wrong installing the command line tools on your machine.
I pasted the output of the commands I ran on a NUC with no Xcode or command line tools installed just to test installation and working of iStats and it worked for me. Use sudo xcode-select -s /Applications/Xcode.app
to switch to the Xcode app. The error you got is either due to Xcode being installed or command line tools not being installed properly.
If you need to use it in scripting I suggest compiling this one instead.
$ git clone https://github.com/lavoiesl/osx-cpu-temp
Cloning into 'osx-cpu-temp'...
remote: Enumerating objects: 143, done.
remote: Counting objects: 100% (22/22), done.
remote: Compressing objects: 100% (17/17), done.
remote: Total 143 (delta 11), reused 12 (delta 5), pack-reused 121
Receiving objects: 100% (143/143), 48.42 KiB | 1.03 MiB/s, done.
Resolving deltas: 100% (68/68), done.
$ cd osx-cpu-temp
$ make
cc -O2 -Wall -framework IOKit -o osx-cpu-temp smc.c
$ ./osx-cpu-temp
39.0 °C
One C file and some headers, not difficult to adjust to your needs and likely easier to use in a shell script unless your shell script is also written in ruby.
Might also be able to do fan speeds.
$ ./osx-cpu-temp -h
usage: osx-cpu-temp <options>
Options:
-F Display temperatures in degrees Fahrenheit.
-C Display temperatures in degrees Celsius (Default).
-T Do not display the units for temperatures.
-c Display CPU temperature (Default).
-g Display GPU temperature.
-a Display ambient temperature.
-f Display fan speeds.
-h Display this help.
That project requires macOS 12, and I have only 10.14:
cc -O2 -Wall -framework IOKit -o osx-cpu-temp smc.c
smc.c:59:43: error: use of undeclared identifier 'kIOMainPortDefault'; did you
mean 'kIOMasterPortDefault'?
result = IOServiceGetMatchingServices(kIOMainPortDefault, matchingDi...
^~~~~~~~~~~~~~~~~~
kIOMasterPortDefault
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/IOKit.framework/Headers/IOKitLib.h:103:19: note:
'kIOMasterPortDefault' declared here
const mach_port_t kIOMasterPortDefault;
^
1 error generated.
make: *** [osx-cpu-temp] Error 1
The documentation for the missing kIOMainPortDefault
is:
I'll try to figure out how to modify the code to make it run on 10.14.
Thank you.