#!/bin/bash # # TP Probe v.0.3 alpha # by 31d1 2005 djbidi@gmail.com # # displays (somewhat accurate) hardware sensor readouts on some current macs. # works on Powerbooks # help [ "$1" == "-h" ] && { echo "usage: $(basename $0) [option|regex]" echo " -h - display this message" echo " -l - also show machine name and type" echo " regex - display only matching lines" exit } # get data sensors=$(ioreg -n IOHWSensor | awk '/location/ || /current-value/ || /"type"/' | sed -e 's/[^"]*"//' -e 's/" =//' -e 's/location//' -e 's/type//' -e 's/"//g' | awk '{ if ((NR % 3) == 0) print $0; else printf $0 " " }') # temperatures require strange manipulation temps=$(echo "$sensors" | grep 'temperature' | awk '{ for(i=1;i<5;i++) if ($i=="current-value") $(i+1)=((( (($(i+1) / 2^13) - ($(i+1) / 2^13) % 1 ) / 2^3) - .5)" C\t"); print $0 }' | sed -e 's/current-value //' -e 's/temperature//') # the rest merely need to be divided by 2^16 therest=$(echo "$sensors" | grep -v 'temperature' | awk '{ for(i=1;i<5;i++) if ($i=="current-value") $(i+1)=(substr((($(i+1)/2^16)"\t"),1,8)); print $0 }' | sed -e 's/current-value //') # optionally display Machine Name and Type [ "$1" == "-l" ] && { system_profiler SPHardwareDataType | awk '/Machine Name/ || /Machine Model/ || /CPU Type/' | sed 's/[^:]*: //' | awk '{printf $0 " " }' machine echo -e "\n$temps\n$therest" exit } # grep for $1 or display all if [ "$1" ]; then echo -e "$temps\n$therest" | grep "$*" else echo -e "$temps\n$therest" fi