#!/bin/bash
SMARTLOG="/var/log/smartd.log"
LOGTIME=`date +%Y.%m.%d-%H:%M:%S`
DEVICES=$( /bin/ls /sys/block -1 | grep "^sd" )
PID_FILE="/run/lock/smartctl-test.lock"
exec 221>${PID_FILE}
flock --exclusive --nonblock 221 ||
{
    echo "Another instance is apparently running."
    exit 1
}
echo ${$}>&221
for DISK in $DEVICES; do
    /usr/sbin/smartctl --test=short /dev/$DISK
    if [ "$?" -ne 0 ] ; then
        echo "$LOGTIME unable to launch the short test:$DISK:1" >> $SMARTLOG
    else
        echo "$LOGTIME smart short test launched:$DISK:0" >> $SMARTLOG
    fi
done
