Get disk list from smartctl scan

This commit is contained in:
Jeremy Gardais 2020-02-19 11:18:25 +01:00
parent 681d1ee0c3
commit 393f9996d2
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 9 additions and 9 deletions

View File

@ -2,18 +2,18 @@
# NOTE: Must be run as root, so you probably need to setup sudo for this. # NOTE: Must be run as root, so you probably need to setup sudo for this.
# Thanks to xymon.com https://www.xymon.com/xymon-cgi/viewconf.sh?smart
if test -f /tmp/dres; then rm -f /tmp/dres; fi if test -f /tmp/dres; then rm -f /tmp/dres; fi
smartctl --scan > /tmp/dscan
# MODIFY below to match your setup - the "scsi-SATA" is pretty generic, but you # MODIFY below to match your setup - the "scsi-SATA" is pretty generic, but you
# can add more disks if you like. E.g. I have a USB disk permanently plugged in. # can add more disks if you like. E.g. I have a USB disk permanently plugged in.
ls /dev/disk/by-id/scsi-SATA_* /dev/disk/by-id/usb-WD* | grep -v -- -part | sort | while read LINE
while read DISK
do do
DRES=`/usr/sbin/smartctl -H -n standby $DISK` DISK=$(echo "${LINE}" | cut -d" " -f1)
TYPE=$(echo "${LINE}" | cut -d" " -f3)
DRES=`/usr/sbin/smartctl -H -d "${TYPE}" -n standby "${DISK}"`
DCODE=$? DCODE=$?
DSTBY=$(( $DCODE & 2 )) DSTBY=$(( $DCODE & 2 ))
DFAIL=$(( $DCODE & 8 )) DFAIL=$(( $DCODE & 8 ))
@ -32,15 +32,15 @@ do
COLOR="3&green" COLOR="3&green"
fi fi
echo "${COLOR} $DISK" echo "${COLOR} $DISK ${TYPE}"
echo "${COLOR} $DISK" | cut -c2- >>/tmp/dres echo "${COLOR} $DISK ${TYPE}" | cut -c2- >>/tmp/dres
echo "" >>/tmp/dres echo "" >>/tmp/dres
echo "$DRES" | egrep -v "^smartctl|^Copyright|^$|^===" >>/tmp/dres echo "$DRES" | egrep -v "^smartctl|^Copyright|^$|^===" >>/tmp/dres
echo "------------------------------------------------------------" >>/tmp/dres echo "------------------------------------------------------------" >>/tmp/dres
echo "" >>/tmp/dres echo "" >>/tmp/dres
echo "" >>/tmp/dres echo "" >>/tmp/dres
done >/tmp/dcheck done < /tmp/dscan >/tmp/dcheck
COLOR=`cat /tmp/dcheck | awk '{print $1}' | sort | uniq | head -1 | cut -c3-` COLOR=`cat /tmp/dcheck | awk '{print $1}' | sort | uniq | head -1 | cut -c3-`
@ -53,7 +53,7 @@ $XYMON $XYMSRV "status ${MACHINE}.smart ${COLOR} SMART health check
`cat /tmp/dres` `cat /tmp/dres`
" "
rm -f /tmp/dres /tmp/dcheck rm -f /tmp/dres /tmp/dcheck /tmp/dscan
exit 0 exit 0