forked from Spearfoot/FreeNAS-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_hdd_temp.sh
75 lines (58 loc) · 2.37 KB
/
get_hdd_temp.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/sh
# Display current temperature of all SMART-enabled drives
# 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.
# 1. A string constant; just key in the devices you want to report on here:
#drives="da1 da2 da3 da4 da5 da6 da7 da8 ada0"
# 2. A systcl-based technique suggested on the FreeNAS forum:
#drives=$(for drive in $(sysctl -n kern.disks); do \
#if [ "$(/usr/local/sbin/smartctl -i /dev/${drive} | grep "SMART support is: Enabled" | awk '{print $3}')" ]
#then printf ${drive}" "; fi done | awk '{for (i=NF; i!=0 ; i--) print $i }')
# 3. A smartctl-based function:
get_smart_drives()
{
gs_drives=$(/usr/local/sbin/smartctl --scan | grep "dev" | awk '{print $1}' | sed -e 's/\/dev\///' | tr '\n' ' ')
gs_smartdrives=""
for gs_drive in $gs_drives; do
gs_smart_flag=$(/usr/local/sbin/smartctl -i /dev/"$gs_drive" | grep "SMART support is: Enabled" | awk '{print $4}')
if [ "$gs_smart_flag" = "Enabled" ]; then
gs_smartdrives=$gs_smartdrives" "${gs_drive}
fi
done
eval "$1=\$gs_smartdrives"
}
drives=""
get_smart_drives drives
# end of method 3.
#############################
# CPU temperatures:
#############################
cores=$(sysctl -a | grep "hw.ncpu" | awk '{print $2}')
printf "=== CPU (%s) ===\n" "${cores}"
cores=$((cores - 1))
for core in $(seq 0 $cores); do
temp="$(sysctl -a | grep "cpu.${core}.temp" | cut -c24-25 | tr -d "\n")"
if [ "$temp" -lt 0 ]; then
temp="--N/A--"
else
temp="${temp}C"
fi
printf "CPU %s: %4s\n" "$core" "$temp"
done
echo ""
#############################
# Drive temperatures:
#############################
echo "=== DRIVES ==="
for drive in $drives; do
serial=$(/usr/local/sbin/smartctl -i /dev/"${drive}" | grep "Serial Number" | awk '{print $3}')
temp=$(/usr/local/sbin/smartctl -A /dev/"${drive}" | grep "194 Temperature" | awk '{print $10}')
if [ -z "$temp" ]; then
temp=$(/usr/local/sbin/smartctl -A /dev/"${drive}" | grep "190 Airflow_Temperature" | awk '{print $10}')
fi
brand=$(/usr/local/sbin/smartctl -i /dev/"${drive}" | grep "Model Family" | awk '{print $3, $4, $5}')
if [ -z "$brand" ]; then
brand=$(/usr/local/sbin/smartctl -i /dev/"${drive}" | grep "Device Model" | awk '{print $3, $4, $5}')
fi
printf "%5.5s: %3.3sC %s %s\n" "$drive" "$temp" "$brand" "$serial"
done