mirror of
https://github.com/Spearfoot/FreeNAS-scripts
synced 2025-12-06 01:23:19 +00:00
Added optional IPMI support for CPU temperatures
This commit is contained in:
105
get_hdd_temp.sh
105
get_hdd_temp.sh
@@ -1,8 +1,32 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Display current temperature of CPU(s) and all SMART-enabled drives
|
||||||
|
|
||||||
|
# Optionally uses IPMI to report temperatures of the system CPU(s)
|
||||||
|
#
|
||||||
|
# If IPMI is disabled (see 'use_ipmi' below) then the script uses
|
||||||
|
# sysctl to report the CPU temperatures. To use IPMI, you must
|
||||||
|
# provide the IPMI host, user name, and user password file.
|
||||||
|
|
||||||
|
# Full path to 'smartctl' program:
|
||||||
smartctl=/usr/local/sbin/smartctl
|
smartctl=/usr/local/sbin/smartctl
|
||||||
|
|
||||||
# Display current temperature of all SMART-enabled drives
|
# IPMI support: set to a postive value to use IPMI for CPU temp
|
||||||
|
# reporting, set to zero to disable IPMI and use 'sysctl' instead:
|
||||||
|
use_ipmi=0
|
||||||
|
|
||||||
|
# IP address or DNS-resolvable hostname of IPMI server:
|
||||||
|
ipmihost=192.168.1.x
|
||||||
|
|
||||||
|
# IPMI username:
|
||||||
|
ipmiuser=root
|
||||||
|
|
||||||
|
# IPMI password file. This is a file containing the IPMI user's password
|
||||||
|
# on a single line and should have 0600 permissions:
|
||||||
|
ipmipwfile=/root/.ssh/password
|
||||||
|
|
||||||
|
# Full path to 'ipmitool' program:
|
||||||
|
ipmitool=/usr/local/bin/ipmitool
|
||||||
|
|
||||||
# We need a list of the SMART-enabled drives on the system. Choose one of these
|
# We need a list of the SMART-enabled drives on the system. Choose one of these
|
||||||
# three methods to provide the list. Comment out the two unused sections of code.
|
# three methods to provide the list. Comment out the two unused sections of code.
|
||||||
@@ -16,45 +40,68 @@ smartctl=/usr/local/sbin/smartctl
|
|||||||
#then printf ${drive}" "; fi done | awk '{for (i=NF; i!=0 ; i--) print $i }')
|
#then printf ${drive}" "; fi done | awk '{for (i=NF; i!=0 ; i--) print $i }')
|
||||||
|
|
||||||
# 3. A smartctl-based function:
|
# 3. A smartctl-based function:
|
||||||
|
|
||||||
get_smart_drives()
|
get_smart_drives()
|
||||||
{
|
{
|
||||||
gs_drives=$("${smartctl}" --scan | grep "dev" | awk '{print $1}' | sed -e 's/\/dev\///' | tr '\n' ' ')
|
|
||||||
|
|
||||||
gs_smartdrives=""
|
gs_smartdrives=""
|
||||||
|
gs_drives=$("$smartctl" --scan | awk '{print $1}')
|
||||||
|
|
||||||
for gs_drive in $gs_drives; do
|
for gs_drive in $gs_drives; do
|
||||||
gs_smart_flag=$("${smartctl}" -i /dev/"$gs_drive" | grep "SMART support is: Enabled" | awk '{print $4}')
|
gs_smart_flag=$("$smartctl" -i "$gs_drive" | grep "SMART support is: Enabled" | awk '{print $4}')
|
||||||
if [ "$gs_smart_flag" = "Enabled" ]; then
|
if [ "$gs_smart_flag" = "Enabled" ]; then
|
||||||
gs_smartdrives=$gs_smartdrives" "${gs_drive}
|
gs_smartdrives="$gs_smartdrives $gs_drive"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
echo "$gs_smartdrives"
|
||||||
eval "$1=\$gs_smartdrives"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
drives=""
|
drives=$(get_smart_drives)
|
||||||
get_smart_drives drives
|
|
||||||
|
|
||||||
# end of method 3.
|
# end of method 3.
|
||||||
|
|
||||||
#############################
|
#############################
|
||||||
# CPU temperatures:
|
# CPU temperatures:
|
||||||
#############################
|
#############################
|
||||||
|
|
||||||
cores=$(sysctl -a | grep "hw.ncpu" | awk '{print $2}')
|
if [ "$use_ipmi" -eq 0 ]; then
|
||||||
printf "=== CPU (%s) ===\n" "${cores}"
|
cpucores=$(sysctl -n hw.ncpu)
|
||||||
cores=$((cores - 1))
|
printf '=== CPU (%s) ===\n' "$cpucores"
|
||||||
for core in $(seq 0 $cores); do
|
cpucores=$((cpucores - 1))
|
||||||
# temp="$(sysctl -a | grep "cpu.${core}.temp" | cut -c24-25 | tr -d "\n")"
|
for core in $(seq 0 $cpucores); do
|
||||||
temp=$(sysctl -a | grep "cpu.${core}.temperature" | awk '{print $2}')
|
temp=$(sysctl -n dev.cpu."$core".temperature)
|
||||||
if [ "$temp" -eq '-1' ]; then
|
if [ "$temp" -lt 0 ]; then
|
||||||
temp="--n/a--"
|
temp="--n/a--"
|
||||||
|
else
|
||||||
|
temp="${temp}C"
|
||||||
|
fi
|
||||||
|
printf 'CPU %2.2s: %5s\n' "$core" "$temp"
|
||||||
|
done
|
||||||
|
echo ""
|
||||||
|
else
|
||||||
|
cpucores=$("$ipmitool" -I lanplus -H "$ipmihost" -U "$ipmiuser" -f "$ipmipwfile" sdr elist all | grep -c -i "cpu.*temp")
|
||||||
|
|
||||||
|
printf '=== CPU (%s) ===\n' "$cpucores"
|
||||||
|
if [ "$cpucores" -eq 1 ]; then
|
||||||
|
temp=$("$ipmitool" -I lanplus -H "$ipmihost" -U "$ipmiuser" -f "$ipmipwfile" sdr elist all | grep "CPU Temp" | awk '{print $10}')
|
||||||
|
if [ "$temp" -lt 0 ]; then
|
||||||
|
temp="-n/a-"
|
||||||
|
else
|
||||||
|
temp="${temp}C"
|
||||||
|
fi
|
||||||
|
printf 'CPU %2s: %5s\n' "$core" "$temp"
|
||||||
else
|
else
|
||||||
temp="${temp}C"
|
for core in $(seq 1 "$cpucores"); do
|
||||||
|
temp=$("$ipmitool" -I lanplus -H "$ipmihost" -U "$ipmiuser" -f "$ipmipwfile" sdr elist all | grep "CPU${core} Temp" | awk '{print $10}')
|
||||||
|
if [ "$temp" -lt 0 ]; then
|
||||||
|
temp="-n/a-"
|
||||||
|
else
|
||||||
|
temp="${temp}C"
|
||||||
|
fi
|
||||||
|
printf 'CPU %2s: [%s]\n' "$core" "$temp"
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
printf "CPU %2.2s: %5s\n" "$core" "$temp"
|
echo ""
|
||||||
done
|
fi
|
||||||
echo ""
|
|
||||||
|
|
||||||
#############################
|
#############################
|
||||||
# Drive temperatures:
|
# Drive temperatures:
|
||||||
@@ -63,21 +110,21 @@ echo ""
|
|||||||
echo "=== DRIVES ==="
|
echo "=== DRIVES ==="
|
||||||
|
|
||||||
for drive in $drives; do
|
for drive in $drives; do
|
||||||
serial=$("${smartctl}" -i /dev/${drive} | grep "Serial Number" | awk '{print $3}')
|
serial=$("$smartctl" -i "$drive" | grep "Serial Number" | awk '{print $3}')
|
||||||
capacity=$("${smartctl}" -i /dev/${drive} | grep "User Capacity" | awk '{print $5 $6}')
|
capacity=$("$smartctl" -i "$drive" | grep "User Capacity" | awk '{print $5 $6}')
|
||||||
temp=$("${smartctl}" -A /dev/${drive} | grep "194 Temperature" | awk '{print $10}')
|
temp=$("$smartctl" -A "$drive" | grep "194 Temperature" | awk '{print $10}')
|
||||||
if [ -z "$temp" ]; then
|
if [ -z "$temp" ]; then
|
||||||
temp=$("${smartctl}" -A /dev/"${drive}" | grep "190 Airflow_Temperature" | awk '{print $10}')
|
temp=$("$smartctl" -A "$drive" | grep "190 Airflow_Temperature" | awk '{print $10}')
|
||||||
fi
|
fi
|
||||||
if [ -z "$temp" ]; then
|
if [ -z "$temp" ]; then
|
||||||
temp="-n/a-"
|
temp="-n/a-"
|
||||||
else
|
else
|
||||||
temp="${temp}C"
|
temp="${temp}C"
|
||||||
fi
|
fi
|
||||||
brand=$("${smartctl}" -i /dev/${drive} | grep "Model Family" | awk '{print $3, $4, $5, $6, $7}')
|
brand=$("$smartctl" -i "$drive" | grep "Model Family" | awk '{print $3, $4, $5, $6, $7}')
|
||||||
if [ -z "$brand" ]; then
|
if [ -z "$brand" ]; then
|
||||||
brand=$("${smartctl}" -i /dev/${drive} | grep "Device Model" | awk '{print $3, $4, $5, $6, $7}')
|
brand=$("$smartctl" -i "$drive" | grep "Device Model" | awk '{print $3, $4, $5, $6, $7}')
|
||||||
fi
|
fi
|
||||||
printf "%6.6s: %5s %-8s %-20.20s %s\n" "$drive" "$temp" "$capacity" "$serial" "$brand"
|
printf '%6.6s: %5s %-8s %-20.20s %s\n' "$(basename "$drive")" "$temp" "$capacity" "$serial" "$brand"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user