summaryrefslogtreecommitdiffstats
path: root/abs/core/xymon/xymon-hddtemp.sh
blob: 0369b4a1929a3f6c8c4402b948380de69e738f07 (plain)
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
#!/bin/sh

# NOTE: Must be run as root, so you probably need to setup sudo for this.

ls /dev/disk/by-id/* | grep -ve '-part' -ve '/wwn-' -ve '/md' |
while read DISK
do
    DISKDEV=`ls -l $DISK | awk -F/ '{print $NF}'`
    DISKNAME=`echo $DISK | awk -F/ '{print $5}' | tr ":" "_"`

    #check if device is optical
    if [[ $DISKDEV == "sr"* ]]
    then
        continue
    fi

    #check if device is mounted
    if ! mount | grep -q /dev/$DISKDEV
    then
        # check if device is used by mdadm
        if ! cat /proc/mdstat | grep -q $DISKDEV
        then
            continue
        fi
    fi

    #check if SMART is disabled and enable
    DRES=`sudo /usr/bin/smartctl -A $DISK`
    if [[ $DRES == *"SMART Disabled. Use option -s with argument 'on'"* ]]
    then
        sudo /usr/bin/smartctl -s on $DISK
        DRES=`sudo /usr/bin/smartctl -A $DISK`
    fi

    hddtemp=`echo "$DRES" | grep Temperature_Celsius | awk '{print $10}'`

    TEMP=": $hddtemp"
    if [[ $hddtemp == "" ]]
    then
        TEMP="- No Temp Sensor Found"
        COLOR="4&clear"
    elif test $hddtemp -gt 55
    then
        COLOR="1&red"
    elif test $hddtemp -ge 50
    then
        COLOR="2&yellow"
    else
        COLOR="3&green"
    fi

    echo "${COLOR} $DISKNAME $TEMP"

done > /tmp/hddcheck

COLOR=`cat /tmp/hddcheck | awk '{print $1}' | sort | uniq | head -1 | cut -c3-`

# Report status to Xymon Server
$XYMON $XYMSRV "status ${MACHINE}.hddtemp ${COLOR} Hard Drive Temperatures (in &degC)

`cat /tmp/hddcheck | cut -c2-`
"

rm -f /tmp/hddcheck

exit 0