Skip to content

Instantly share code, notes, and snippets.

@fragolinux
Created March 28, 2017 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fragolinux/a220afaf37329e6f043f876bb7bc8963 to your computer and use it in GitHub Desktop.
Save fragolinux/a220afaf37329e6f043f876bb7bc8963 to your computer and use it in GitHub Desktop.
temp.sh
#!/bin/bash
# credits to DietPi
# to check it constantly, run: watch bash temp.sh
CPU_TEMP_CURRENT='Unknown'
CPU_TEMP_PRINT='Unknown'
ACTIVECORES=$(grep -c processor /proc/cpuinfo)
#Array to store possible locations for temp read.
aFP_TEMPERATURE=(
'/sys/class/thermal/thermal_zone0/temp'
'/sys/devices/platform/sunxi-i2c.0/i2c-0/0-0034/temp1_input'
'/sys/class/hwmon/hwmon0/device/temp_label'
)
Obtain_Cpu_Temp(){
for ((i=0; i<${#aFP_TEMPERATURE[@]}; i++))
do
if [ -f "${aFP_TEMPERATURE[$i]}" ]; then
CPU_TEMP_CURRENT=$(cat "${aFP_TEMPERATURE[$i]}")
# - Some devices (pine) provide 2 digit output, some provide a 5 digit ouput.
# So, If the value is over 1000, we can assume it needs converting to 1'c
if (( $CPU_TEMP_CURRENT >= 1000 )); then
CPU_TEMP_CURRENT=$( echo -e "$CPU_TEMP_CURRENT" | awk '{print $1/1000}' | xargs printf "%0.0f" )
fi
if (( $CPU_TEMP_CURRENT >= 70 )); then
CPU_TEMP_PRINT="\e[91mWarning: $CPU_TEMP_CURRENT'c\e[0m"
elif (( $CPU_TEMP_CURRENT >= 60 )); then
CPU_TEMP_PRINT="\e[38;5;202m$CPU_TEMP_CURRENT'c\e[0m"
elif (( $CPU_TEMP_CURRENT >= 50 )); then
CPU_TEMP_PRINT="\e[93m$CPU_TEMP_CURRENT'c\e[0m"
elif (( $CPU_TEMP_CURRENT >= 40 )); then
CPU_TEMP_PRINT="\e[92m$CPU_TEMP_CURRENT'c\e[0m"
elif (( $CPU_TEMP_CURRENT >= 30 )); then
CPU_TEMP_PRINT="\e[96m$CPU_TEMP_CURRENT'c\e[0m"
else
CPU_TEMP_PRINT="\e[96m$CPU_TEMP_CURRENT'c\e[0m"
fi
break
fi
done
}
Obtain_Cpu_Temp
echo -e Cores: $ACTIVECORES at $CPU_TEMP_PRINT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment