-
Notifications
You must be signed in to change notification settings - Fork 0
/
drive_temp.sh
96 lines (82 loc) · 2.38 KB
/
drive_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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash
# Specify your email address here:
email="[email protected]"
logfile="/tmp/hd_temp_report.tmp"
smartctl=/usr/local/sbin/smartctl
critTemp=45
subject="CRITIAL HD TEMP - SERVER NAS"
send_pb_alert()
{
/root/scripts/push.sh "HD TEMP ALERT" "Your Server Hard Drives are HOT!"
touch /root/scripts/hd_temp_alert_sent
}
send_email_alert()
{
### Set email headers
(
echo "To: ${email}"
echo "Subject: ${subject}"
echo "Content-Type: text/html"
echo "MIME-Version: 1.0"
printf "\r\n"
) > ${logfile}
### Set email body ###
echo "<pre style=\"font-size:14px\">" >> ${logfile}
(
echo "There is a problem with the temperature on one or more hard drives on your FreeNAS Server."
echo ""
echo "It is HIGHLY advisable that you relocate the servers to a cooler location before "
echo "any of your hard drives are damaged!"
echo ""
echo ""
echo "This is an automated email, please do not reply!"
echo ""
echo ""
echo ""
echo "You will only receive this email once per day. To immediately re-enable this alert, please ssh into your FreeNAS "
echo "server and remove this file: "
echo ""
echo ""
echo " /root/scripts/hd_temp_alert_sent"
echo ""
echo ""
echo " WARNING WARNING WARNING "
echo " Failure to resolve this hard drive temperature issue can lead to failure of the NAS and of Plex!!"
echo ""
) >> ${logfile}
echo "</pre>" >> ${logfile}
sendmail ${email} < ${logfile}
rm ${logfile}
touch /root/scripts/hd_temp_alert_sent
}
get_smart_drives()
{
gs_drives=$("${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=$("${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
for drive in $drives
do
(
drive_temp=`smartctl -a /dev/${drive} | awk '/Temperature_Celsius/{print $0}' | awk '{print $10}'`
if (( $drive_temp > $critTemp )); then
echo $drive_temp
if [ ! -e "/root/scripts/hd_temp_alert_sent" ]; then
send_email_alert
send_pb_alert
else
exit 1
fi
else
echo $drive_temp
fi
)
done