Using terminal to get current fan speed? [duplicate]

Solution 1:

smcFanControl

You mention in your comments having smcFanControl installed; this open source project includes the command line tool smc. You can use smc to get fan speed information via Terminal.app:

smc -f

See the smc manual page for more options.

Since Mac OS X 10.5, you need to use a third party piece of software to access the fan speed information. It appears no tool, installed by default on OS X, exposes this information through the terminal.

The open source project Fan Control includes a command line tool that provides fan speed information. This article, OS X: Current CPU temperature on command line, talks about the project and how to extract the fan speed:

smc -k TC0D -r | sed 's/.*bytes \(.*\))/\1/' |sed 's/\([0-9a-fA-F]*\)/0x\1/g' | perl -ne 'chomp; ($low,$high) = split(/ /); print (((hex($low)*256)+hex($high))/4/64); print "C\n";'

Avoid spindump

spindump requires administrator privileges and when run manually, spindump samples user and kernel stacks for every process in the system. This is a computationally expensive process, even when run for one second.

Alternatives

Other tools and applications exist, including Temperature Monitor. See Can I get the CPU temperature and fan speed from the command line in OS X?

Pre-Mac OS X 10.5

This article, get sensor information, shows how to use ioreg to extract the fan speed information with:

ioreg -c IOHWSensor | grep -B3 -A11 '"type" = "fanspeed"'

The above article and the script it contains was designed for Mac OS X 10.4.3.

See also:

  • Reading hardware information from command line with built-in tools.
  • Determining Fan Speeds

Solution 2:

On Mojave, spindump doesn't seem to list the fan speed. Noticed that powermetrics does, though. Try running sudo powermetrics -i 200 --samplers smc | grep Fan instead.

Solution 3:

Oneliner - gives output after 1 second using spindump

SD=~/.spindump.txt;sudo rm $SD;sudo spindump 1 1 -file "$SD" ;grep "Fan speed" $SD

Each seperate part explained:

SD=~/.spindump.txt: create a variable with the .spindump.txt log

sudo rm $SD: clean up your tmp file using sudo rights, as the file was created by sudo spindump.

sudo spindump 1 1 -file $SD: run spindump as root (it only runs as root) for 1 second in 1 interval and output the file to your $SD

grep "Fan speed" $SD: get the line that says "Fan speed"

It is very unfortunate that we need sudo rights to run this script.


> SD=~/.spindump.txt;sudo rm $SD;sudo spindump 1 1 -file "$SD" ;grep "Fan speed" $SD

Password:
Sampling all processes for 1 seconds with 10 milliseconds of run time between samples
Focusing on launchd [1]
Sampling completed, processing symbols...
Spindump analysis written to file /Users/CousinCocaine/.spindump.txt
Fan speed:       2302 rpm

Solution 4:

Try sudo powermetrics -s smc. To change the refresh rate, use sudo powermetrics -s smc -i <milliseconds>.