WizardKit/.bin/Scripts/linux-old/hw-diags-sensors
2017-12-17 21:22:53 -07:00

42 lines
1.3 KiB
Bash
Executable file

#!/bin/bash
#
## Wizard Kit: HW Diagnostics - Sensors
LOG_DIR="$1"
function usage {
echo "Usage: $0 log-dir"
echo " e.g. $0 /tmp/tmp.7Mh5f1RhSL9001"
}
# Create directory if necessary
if [ ! -d "$LOG_DIR" ]; then
LOG_DIR="$(mktemp -d)"
fi
# Run Sensor loop
if sensors >/dev/null 2>&1; then
while :; do
sensors -A | grep -E -i -v '(N/A|RPM|\d+\s+V\s+|^\s*$)' > "$LOG_DIR/sensors.out" 2>/dev/null
# Colorize
# Blue: All temps (superseeded by other colors below)
sed -i -r 's#(\+[0-9]+\.[0-9].C)#\\e[34m\1\\e[0m#g' "$LOG_DIR/sensors.out" >/dev/null 2>&1
# Green >= 60* C
sed -i -r 's#(\+6[0-9]\.[0-9].C)#\\e[32m\1\\e[0m#g' "$LOG_DIR/sensors.out" >/dev/null 2>&1
# Yellow >= 70* C
sed -i -r 's#(\+7[0-9]\.[0-9].C)#\\e[33m\1\\e[0m#g' "$LOG_DIR/sensors.out" >/dev/null 2>&1
# Orange >= 80* C
sed -i -r 's#(\+(8[0-9]|9[0-4])\.[0-9].C)#\\e[31\;1m\1\\e[0m#g' "$LOG_DIR/sensors.out" >/dev/null 2>&1
# Red >= 95* C
sed -i -r 's#(\+(9[5-9]|1[0-9][0-9])\.[0-9].C)#\\e[31m\1\\e[0m#g' "$LOG_DIR/sensors.out" >/dev/null 2>&1
# Output data
clear
echo -e "$(cat "$LOG_DIR/sensors.out")"
sleep 1s
done
else
echo -e "\e[33mNo sensors found!\nPlease monitor temperatures manually\e[0m"
sleep 1h
fi