This repository has been archived by the owner on May 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck_drive.sh
48 lines (42 loc) · 1.86 KB
/
check_drive.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
#!/bin/bash
# This script checks for drive state (SMART status OK & temperature between constructor range)
# If drive state is not satisfying, the front panel LED will blink yellow/red
# See README.md for commands description
# Put the script in crontab : sudo crontab -e then add the line "* * * * * /root/check_drive.sh"
max_threshold="65"
min_threshold="0"
temperature=`/usr/sbin/smartctl /dev/sda -A | /bin/grep Temperature_Celsius | /usr/bin/awk '{print $10}'`
echo temperature=$temperature C
echo max_threshold=$max_threshold C
echo min_threshold=$min_threshold C
if [ $temperature \> $max_threshold ];
then
echo "Disk is overheating";
echo yellow > /sys/class/leds/system_led/color
echo blink > /sys/class/leds/system_led/blink
echo "["`date`"] Disk temperature=${temperature}C OVERHEAT !" >> /tmp/temperature.log
elif [ $min_threshold \> $temperature ];
then
echo "Disk is freezing";
echo yellow > /sys/class/leds/system_led/color
echo blink > /sys/class/leds/system_led/blink
echo "["`date`"] Disk temperature=${temperature}C TOO COLD !" >> /tmp/temperature.log
else
echo "Disk is in recommended temperature range"
# No led modification for nominal case, to display other system led notifications
fi;
smart_status=`/usr/sbin/smartctl -q silent -a /dev/sda; echo $?`
if [ "$smart_status" = "1" ];
then
echo "SMART status failed !"
echo red > /sys/class/leds/system_led/color
echo blink > /sys/class/leds/system_led/blink
echo "["`date`"] SMART status failed !" >> /tmp/smart.log
/usr/sbin/smartctl /dev/sda -H >> /tmp/smart.log
/usr/sbin/smartctl /dev/sda -A >> /tmp/smart.log
/usr/sbin/smartctl /dev/sda --log=error >> /tmp/smart.log
/usr/sbin/smartctl /dev/sda --log=selftest >> /tmp/smart.log
else
echo "SMART status OK"
# No led modification for nominal case, to display other system led notifications
fi;