Skip to content

Instantly share code, notes, and snippets.

@avafinger
Created January 1, 2018 20:45
Show Gist options
  • Save avafinger/099d4e1a6de0b7c9fbea087e3185b02f to your computer and use it in GitHub Desktop.
Save avafinger/099d4e1a6de0b7c9fbea087e3185b02f to your computer and use it in GitHub Desktop.
#!/bin/sh
# Bsed on tkaiser and longsleep script
# Run this script like `sudo ./h2_health.sh -w`.
#
set -e
if [ "$(id -u)" -ne "0" ]; then
echo "This script requires root."
exit 1
fi
print() {
printf "%-15s: %s %s\n" "$1" "$2 $3" "$4"
}
cpu_frequency() {
local cur=$(cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq)
local mhz=$(awk "BEGIN {printf \"%.f\",$cur/1000}")
print "CPU freq" $mhz "MHz"
}
scaling_govenor() {
local gov=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor)
print "Governor" $gov
}
cpu_count() {
local cpus=$(grep -c processor /proc/cpuinfo)
print "CPU count" $cpus
}
soc_temp() {
local temp=$(cat /sys/devices/virtual/thermal/thermal_zone0/temp)
print "SOC Temp" $temp
"C"
}
all() {
# echo 1 > /sys/class/gpio_sw/normal_led/data
cpu_frequency
cpu_count
scaling_govenor
soc_temp
# echo 0 > /sys/class/gpio_sw/normal_led/data
}
usage() {
echo "Usage: $0 [-w] [-h]"
}
WATCH=""
for i in "$@"; do
case $i in
-w)
WATCH=1
shift
;;
-h|--help)
usage
exit 0
;;
*)
usage
exit 1
;;
esac
done
if [ -n "$WATCH" ]; then
exec watch -n2 "$0"
else
all
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment