Skip to content

Instantly share code, notes, and snippets.

@jsfaint
Created July 11, 2017 09:16
Show Gist options
  • Save jsfaint/85854b6d1dd80acfd7acaccd61633c10 to your computer and use it in GitHub Desktop.
Save jsfaint/85854b6d1dd80acfd7acaccd61633c10 to your computer and use it in GitHub Desktop.
Get hwmon temperature on Linux via sysfs
#!/bin/bash
hwmon_sysfs="/sys/class/hwmon"
list=$(find "$hwmon_sysfs"/*)
for i in $list; do
if [ -e "$i/name" ]; then
sensor="$i"
else
sensor="$i/device"
fi
cat "$sensor/name"
count=$(find "$sensor"/temp*_input | wc -l)
for((j=1; j<=count; j++)); do
if [ -e "$sensor"/temp"$j"_label ]; then
name=$(awk '{print $1}' < "$sensor"/temp"$j"_label)
else
name="temp$j"
fi
if [ -e "$sensor"/temp"$j"_input ]; then
temp=$(awk '{print $1}' < "$sensor"/temp"$j"_input)
temp=$(echo "scale=2; $temp / 1000" | bc)
else
temp="N/A"
fi
echo -ne "$name $temp\n"
done
echo
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment