Last active
July 21, 2019 06:48
-
-
Save estysdesu/b83ec56ef58e1e168998ac60e3db505d to your computer and use it in GitHub Desktop.
[SMC-ish: continuously watch fan and CPU temperature metrics] #smc #powermetrics #osx #macos #fan #temp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# https://github.com/estysdesu/dotFiles/blob/master/bin/lapHeater | |
warning=90 | |
bad=120 | |
nc='\033[0m' # no color | |
red='\033[0;31m' | |
yellow='\033[0;33m' | |
green='\033[0;32m' | |
blue='\033[0;34m' | |
while true | |
do | |
# call powermetrics; grep keys; grep digits only | |
out=$(sudo powermetrics -n 1 -i 1000 | grep -e 'CPU die temperature:.*' -e 'Fan:.*' | grep -o '[0-9\.]\+') | |
# read -a == readarry w/ delim as space; <<< redirect sends string | |
read -d' ' -a outArr <<< "$out" | |
# try integer comparison, if fail, use bash built in basic calculator for comparison of floats | |
if (( $(echo "${outArr[1]} > ${bad}" | bc -l) )) ; then | |
color=${red} | |
elif (( $(echo "${outArr[1]} > ${warning}" | bc -l) )); then | |
color=${yellow} | |
else | |
color=${blue} | |
fi | |
printf "${color}CPU temp: ${outArr[1]}*C${nc}\t\t\t${color}Fan: ${outArr[0]}rpm${nc}\r" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment