Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

CPU temperature and hardware sensor readouts in bash UNIX
While hunting around in ioreg I found a bunch of hardware sensor readouts, including CPU and GPU temperatures. I had no idea this stuff was available without a compiled app, so I excitedly whipped up a bash script (tp v0.1) to display the values.

I realize that the number of sensors and ioreg formatting varies wildly between various Macs, so I sacrificed some formatting to try and make sure that it will display all possible sensors on a given machine, and at least be legible.

This should work on most recent Macs, but if you try this script out, please post a comment stating what machine you are running -- especially if it displays any garbage on your machine, as I'd like to know so I can fix it.

Download, chmod a+x scriptname, put in your PATH, and tp -h for help.

[robg adds: I tested this, and it worked well on my PowerBook. Here's what it spit out:
$ tp -l
PowerBook G4 12"  PowerBook6,4  PowerPC G4  (1.1)  
45.25    HDD BOTTOMSIDE Celsius
48       CPU TOPSIDE Celsius
54.75    GPU ON DIE Celsius
0.99316  CPU CORE volts
0        REAR MAIN ENCLOSURE fan RPM
28       BATTERY Celsius
I have also mirrored the script on macosxhints.com, in case it vanishes from the above link...]
    •    
  • Currently 2.40 / 5
  You rated: 2 / 5 (5 votes cast)
 
[84,674 views]  

CPU temperature and hardware sensor readouts in bash | 26 comments | Create New Account
Click here to return to the 'CPU temperature and hardware sensor readouts in bash' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
CPU temperature and hardware sensor readouts in bash
Authored by: wgscott on Oct 25, '05 06:52:39AM

I only get this:


% tp.sh -l
PowerBook G4 15" PowerBook3,5 PowerPC G4 (3.2)


(nothing else)



[ Reply to This | # ]
CPU temperature and hardware sensor readouts in bash
Authored by: nsxpower on Oct 25, '05 07:35:16AM

PowerBook G4 Titanium don't have a temperature sensor, hence the reason why the script wont give you a proper read out. Rev.A AliBooks and up have these sensors, as well as most G3 PBooks/iBooks.



[ Reply to This | # ]
CPU temperature and hardware sensor readouts in bash
Authored by: wgscott on Oct 25, '05 09:43:30AM

I have a little application called "Temperature Monitor Lite" that reads the CPU temp and puts it in the menu bar.

So the information must be made available by the system.



[ Reply to This | # ]
CPU temp & HW readouts - macmini doesnt have sensors?!
Authored by: zahadum on Jun 07, '06 04:55:19PM
it would be useful if there was list of which machines had which sensors ... once again apple cant even do the basics; hopefully someones else knows. a gui variation of this script returns almost no info at all for the macminbi :-( cf: http://bbs.applescript.net/viewtopic.php?pid=47578 sigh.

---
mailto:osxinfo _at_ yahoo.ca


[ Reply to This | # ]

CPU temperature and hardware sensor readouts in bash
Authored by: 31d1 on Oct 25, '05 07:50:32AM

If you aren't getting any data with this script, look at the output of `ioreg -n IOHWSensor | more`. If there aren't any sections that look like:

| | | | "Power Management protected data" = "{ theNumberO$
| | | | "polling-period" = 5
| | | | "current-value" = 2850816
| | | | "low-threshold" = 0
| | | | "location" = "HDD BOTTOMSIDE"
| | | | "type" = "temperature"
| | | | "high-threshold" = 3538944
| | | | "CFBundleIdentifier" = "com.apple.driver.AppleHWS$
| | | | "IOClass" = "IOHWSensor"
| | | | "IOPropertyMatch" = {"device_type"="temp-sensor"}
| | | | "version" = 1
| | | | "zone" = <00000000>
| | | | "IOProbeScore" = 0
| | | | "Power Management private data" = "{ this object $
| | | | "IOMatchCategory" = "IODefaultMatchCategory"
| | | | "IOProviderClass" = "IOService"
| | | | "sensor-id" = 0

then this thing won't work.

If there ARE some sections like that, then my parsing is off and I should have to fix that.



[ Reply to This | # ]
CPU temperature and hardware sensor readouts in bash
Authored by: 31d1 on Oct 25, '05 07:46:24AM

Hi, I wrote this script, and since I sent it in a few days ago a few things have come to my attention. Basically, I was informed that:

"Your function, by coincidence, outputs a value that is ‘close' on some machines when compared to values spewed by some other tools that do the correct interpretation leading to believe that the problem is a simple one.
The correct reading for powerbooks goes like this: The value written in the registry is actually encoded to the hardware sensor. On most machines, the value is a 32 bit int, with the upper word being the degrees in C and the lower word the fractional part of the temperature.
On other machines the value may not even be a temperature, but just some seed for the fan, or needed to be read from the fan itself. In those cases the actual temp cannot be deduced by looking at this value without having the calibration data for the fan (in prom). As you can see this ends up being quite a bit of work it requires custom code for each of the machines or sensor types."

I'm pretty much a n00b at computer science, and this confused me to no end, so I ended up asking metafilter for help, here:

http://ask.metafilter.com/mefi/25932

and the upshot seemed to be that (for temperature sensors) a more accurate value than (n/2^16) is (( n / 2^13 - n / 2^13 % 1 ) / 2^3) - .5).

I've made up a version of the script that uses that value at http://cutup.org/_2tp, but on my machine it seems to output the same value as before less .5 degrees.

I'm not sure if thats coincidence or if I still have this wrong, and I would appreciate any input on the matter.



[ Reply to This | # ]
CPU temperature and hardware sensor readouts in bash
Authored by: GlowingApple on Oct 25, '05 11:57:36AM

The temperature widget I use shows a value that's 0.5 lower than your first script shows for me. Using the new script, the numbers are off by less than 0.2 on average (yours being a bit lower). Definitely well within good enough range for me.

Thanks for the script, it's nice to have a command line way of checking this.

---
Jayson --When Microsoft asks you, "Where do you want to go today?" tell them "Apple."



[ Reply to This | # ]
CPU temperature and hardware sensor readouts in bash
Authored by: iamdw on Oct 25, '05 10:22:22PM
Wonderful script 31d1, and after reading through the Ask Metafilter thread I see your confusion, though i don't completely understand it as i'm an even fresher n00b than you. Anywhen, my math skill are rather weak, and i was wondering if a Celsius to Fahrenheit conversion is a simple switch of the "
$(i+1)=((( (($(i+1) / 2^13) - ($(i+1) / 2^13) % 1 ) / 2^3) - .5)" Ct")
" formula or something more complext in translating the output from hex etc? If it is, don't worry about it... get the accuracy confusion out of the way first. That said, us Fahrenheit users would love an °F output. Anyone up for the challenge? I've dicking around with it bout as i said, my math is weak...

[ Reply to This | # ]
CPU temperature and hardware sensor readouts in bash
Authored by: Cerberus on Oct 25, '05 08:21:27AM

G5 Dual 2.5Ghz - Seems to work great

tp -l
Power Mac G5 PowerMac7,3 PowerPC G5 (3.0)
29 DRIVE BAY Celsius
51.25 BACKSIDE Celsius
70.5 U3 HEATSINK Celsius
0 SLOT 12V power
0 SLOT 5V power
0 SLOT 3.3V power
0.09988 SLOT COMBINED power
59.25 CPU A AD7417 AMB Celsius
0.00878 CPU A AD7417 AD1 adc
0.00927 CPU A AD7417 AD2 adc
0.00772 CPU A AD7417 AD3 adc
0.00308 CPU A AD7417 AD4 adc
55.5 CPU B AD7417 AMB Celsius
0.00856 CPU B AD7417 AD1 adc
0.00929 CPU B AD7417 AD2 adc
0.00772 CPU B AD7417 AD3 adc
0.00343 CPU B AD7417 AD4 adc



[ Reply to This | # ]
Didn't work for me...
Authored by: Eric3 on Oct 25, '05 08:34:59AM

I have a blue G3 tower, motherboard rev. 2, with an upgraded 400MHz G4 inside. All it printed out was a blank line. Could it be that my upgraded CPU's sensors are incompatible with the original ones, or were there never any sensors there to begin with?



[ Reply to This | # ]
CPU temperature and hardware sensor readouts in bash
Authored by: uchuugaka on Oct 25, '05 09:05:46AM

works as expected, though I had to type
./tp.sh
to run it...hmm.
I'm not so hot w/CLI stuff tho.
Interestingly, the fan rpm is 0
I've never heard this ibook G4's fan come on.
even under intense processing.



[ Reply to This | # ]
CPU temperature and hardware sensor readouts in bash
Authored by: sfn on Oct 25, '05 09:12:03AM

Excellent, I have been looking for something like this to use rather than VNCing into my server box to check temperatures.

But, on a PowerMac G5 I get this:

Power Mac G5 PowerMac7,3 PowerPC G5 (3.0)
32 DRIVE BAY Celsius
43.375 BACKSIDE Celsius
56.75 U3 HEATSINK Celsius
0 SLOT 12V power
0 SLOT 5V power
0 SLOT 3.3V power
0.03213 SLOT COMBINED power
49.75 CPU A AD7417 AMB Celsius
0.00979 CPU A AD7417 AD1 adc
0.00535 CPU A AD7417 AD2 adc
0.00804 CPU A AD7417 AD3 adc
0.00256 CPU A AD7417 AD4 adc
42.5 CPU B AD7417 AMB Celsius
0.00875 CPU B AD7417 AD1 adc
0.00291 CPU B AD7417 AD2 adc
0.00801 CPU B AD7417 AD3 adc
0.00102 CPU B AD7417 AD4 adc

Note, the CPU AMB readings don't change over time for me. Only the U3 HEATSINK, AD1, AD4 do.

-s

---
-sfn



[ Reply to This | # ]
CPU temperature and hardware sensor readouts in bash
Authored by: mark hunte on Oct 25, '05 10:21:07AM
The first script seems to work ok on my G4 Powerbook 1.5 ghz For people like me who do not always use terminal I put it into a applescript for use with hotkeys
set get_temp to do shell script "path/to/script/tp -l"
display dialog get_temp buttons {"OK"} default button 1
should be very easy to put in Automator and you may want to put the 'display dialog in a tell block to get the finder to activate.

---
mh

[ Reply to This | # ]

CPU temperature and hardware sensor readouts in bash
Authored by: mbroughtn on Oct 25, '05 09:15:22AM

No data reported for either a B&W G3/300 Rev 1 or a Mac Mini 1.42. Neither apparently have temperature sensors.



[ Reply to This | # ]
PowerBook G4 12" Results
Authored by: lilkeezy on Oct 25, '05 11:21:08AM

PowerBook G4 12" PowerBook6,1 PowerPC G4 (3.3)
47.75 GPU TOPSIDE Celsius
50.75 CPU BOTTOMSIDE Celsius



[ Reply to This | # ]
'05 12" iBook - works for me
Authored by: FFFish on Oct 25, '05 11:26:59AM

Checked against Temperature Monitor Lite, all values within a degree of agreement.



[ Reply to This | # ]
CPU temperature and hardware sensor readouts in bash
Authored by: outchy on Oct 25, '05 07:59:41PM

you should create a widget for this and submit it to apple. is there a way to get around the whole 'path' thing? :)



[ Reply to This | # ]
CPU temperature and hardware sensor readouts in bash
Authored by: tokenfirstyear on Oct 26, '05 02:29:35AM

iBook G4 PowerBook6,7 PowerPC G4 (1.2)
40 PWR/MEMORY BOTTOMSIDE Celsius
43 CPU BOTTOMSIDE Celsius
45.75 GPU BOTTOMSIDE Celsius
0.97876 CPU CORE volts
0 REAR MAIN ENCLOSURE fan RPM
25 BATTERY Celsius

Pretty cool, huh?



[ Reply to This | # ]
CPU temperature and hardware sensor readouts in bash
Authored by: Greedo on Oct 26, '05 08:35:31AM
Not much output on my iMac (non-iSight version). I thought I'd get more:
iMac G5  PowerPC G5  (3.0)  
0.00932  CPU T-Diode temp
0.00308  CPU Current Amps
0.01248  CPU Voltage volts
53       Hard drive Celsius


[ Reply to This | # ]
CPU temperature and hardware sensor readouts in bash
Authored by: albertoricart on Oct 27, '05 06:51:13AM

Hello,

I wrote a similar thing as a dashboard widget (http://www.smartsoft.com), and found that the problem is actually quite a bit more complex than expected.
The value in the registry is an encoded value. And the encoding/meaning of the values varies depending on the machine.

So for example, the correct reading for powerbooks goes like this: The value written in the registry is actually encoded to the hardware sensor. On most machines, the value is a 32 bit int, with the upper word being the degrees in C and the lower word the fractional part of the temperature.

On other machines the value may not even be a temperature, but just some seed for the fan, or needed to be read from the fan itself. In those cases the actual temp cannot be deduced by looking at this value without having the calibration data for the fan (in prom). As you can see this ends up being quite a bit of work it requires custom code for each of the machines or sensor type.



[ Reply to This | # ]
reference app to check output: HardwareMonitor
Authored by: voldenuit on Oct 29, '05 05:12:58PM

To check results, you might want to use this app:

http://bresink.de/osx/HardwareMonitor.html

as a reference.

The guy who wrote it has quite some experience and most probably got it right.



[ Reply to This | # ]
CPU temperature and hardware sensor readouts in bash
Authored by: david-bo on Oct 30, '05 05:38:10AM

Worked on my 12" PB (Tiger)

46.5 HDD BOTTOMSIDE Celsius
46.25 CPU TOPSIDE Celsius
58.75 GPU ON DIE Celsius
1.1228 CPU CORE volts
5720 REAR MAIN ENCLOSURE fan RPM
32 BATTERY Celsius

However, on my Pismo (Panther), I got sed-error:

sed: option requires an argument -- e
usage: sed script [-Ean] [-i extension] [file ...]
sed [-an] [-i extension] [-e script] ... [-f script_file] ... [file ...]
./tp: line 3: s/type//: No such file or directory
sed: option requires an argument -- e
usage: sed script [-Ean] [-i extension] [file ...]
sed [-an] [-i extension] [-e script] ... [-f script_file] ... [file ...]
./tp: line 5: s/temperature/Celsius/: No such file or directory
./tp: line 6: s/current/Amps/: No such file or directory


Any ideas why?

---
http://www.google.com/search?as_q=%22Authored+by%3A+david-bo%22&num=10&hl=en&ie=ISO-8859-1&btnG=



[ Reply to This | # ]
CPU temperature and hardware sensor readouts in bash
Authored by: marc_ on Nov 26, '05 05:50:00AM

Hi,

on my PowerBook i get the following output:

PowerBook G4 15" PowerBook5,6 PowerPC G4 (1.2)
CPU/INTREPID BOTTOMSIDE Celsius 23.5
CPU BOTTOMSIDE Celsius 21.25
PWR SUPPLY BOTTOMSIDE Celsius 19.25
1.25713 CPU CORE volts
0 REAR LEFT EXHAUST fan RPM
0 REAR RIGHT EXHAUST fan RPM
TRACK PAD Celsius 17.5
BATT-TEMP temp 18
0 BATT-CURRENT Amps

so far so good. what makes me a little bit concerned is the fact that the temperatures displayed never change even when i can clearly feel that the machine is getting hotter.... My impression is that the script only displays the tempeatures at startup - looks like the values in ioreg never get updated..... It shouldn't be like this, should it?? Do i have to contact the customer service or what.

cheers



[ Reply to This | # ]
CPU temperature and hardware sensor readouts in bash
Authored by: m1ss1ontomars2k4 on Dec 15, '05 10:37:17PM
iBook G4  PowerBook6,7  PowerPC G4 (1.2)  ppc7450

54.25 C  PWR/MEMORY BOTTOMSIDE 
66 C     CPU BOTTOMSIDE 
63.75 C  GPU BOTTOMSIDE 
27.5 C   BATTERY 
1.13141  CPU CORE voltage
6506     REAR MAIN ENCLOSURE fanspeed


[ Reply to This | # ]
CPU temperature and hardware sensor readouts in bash
Authored by: davidyorke on Mar 20, '06 11:12:57AM

I ran this script (nice job) and got similar values to "temperature monitor". However, that app explicitly states that the values only represent the values at start up and don't change.

I looked at ioreg and noticed that the polling period for the temperature sensors is 18446744073709551615. if that's seconds, then it represents a little over half a trillion years.

Is anyone aware of a way to change these values so polling is more frequent?



[ Reply to This | # ]
CPU temperature check
Authored by: dgerman on Jul 24, '09 12:08:46PM
After revising script on my iBook G4
was: ioreg changed to: /usr/sbin/ioreg and named it sensors.sh

I created the script sensorChk.sh:
export hisensor=`/Users/me/sensors.sh | sort | tail -n1`
export hidigits=`echo $hisensor | cut -c1-2`
if [ $hidigits -gt 50 ]; then
echo $hisensor
say "Pardon me! , I'm hot, and I need a break!"
fi

Then added this to crontab:
* * * * * /Users/me/sensorChk.sh

This checks the sensors every minute.
You might need to tweak the 50

[ Reply to This | # ]