2016-12-14 20:26:15 -06:00
|
|
|
#!/bin/bash
|
|
|
|
|
2016-12-14 22:57:46 -06:00
|
|
|
if [[ -z $OUTPUT_DIR ]] ; then
|
|
|
|
source scan-dmidecode
|
|
|
|
fi
|
|
|
|
|
2016-12-15 18:06:32 -06:00
|
|
|
source test-variables
|
2016-12-15 22:08:43 -06:00
|
|
|
if [[ "$1" != "skip-scan" ]] ; then
|
|
|
|
scan-hdd # Always rescan
|
|
|
|
fi
|
|
|
|
if [[ "$1" == "force" ]] ; then
|
|
|
|
rm -f $OUTPUT_DIR/disk/*.badblocks.result
|
2016-12-14 22:57:46 -06:00
|
|
|
fi
|
|
|
|
|
2016-12-15 18:06:32 -06:00
|
|
|
MAXWAIT=9
|
2016-12-15 05:06:33 -06:00
|
|
|
JOBS=0
|
2016-12-15 22:08:43 -06:00
|
|
|
echo -n "BEGIN: " >> $OUTPUT_DIR/badblocks.log
|
|
|
|
date >> $OUTPUT_DIR/badblocks.log
|
2016-12-14 22:57:46 -06:00
|
|
|
for DISK in `cat $OUTPUT_DIR/disk.lst \
|
|
|
|
| sed 's/#.*$//' \
|
|
|
|
| cut -d ':' -f 1`
|
|
|
|
do
|
|
|
|
SERIAL=`cat $OUTPUT_DIR/disk.lst \
|
|
|
|
| grep $DISK \
|
|
|
|
| cut -d ':' -f 2`
|
2016-12-15 22:08:43 -06:00
|
|
|
if [[ -f $OUTPUT_DIR/disk/$SERIAL.badblocks.result ]] ; then
|
|
|
|
cat $OUTPUT_DIR/disk/$SERIAL.badblocks.result \
|
|
|
|
| sed 's/Process [0-9]\+/Test complete/'
|
|
|
|
cat $OUTPUT_DIR/disk/$SERIAL.badblocks.result \
|
|
|
|
| sed 's/Process [0-9]\+/Result found/' \
|
|
|
|
>> $OUTPUT_DIR/badblocks.log
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
JOBS=$(( JOBS + 1 ))
|
2016-12-15 18:06:32 -06:00
|
|
|
echo -n "Process $JOBS: Testing disk $DISK with badblocks ..."
|
2016-12-15 22:08:43 -06:00
|
|
|
echo -n "Process $JOBS : Disk $DISK : " >> $OUTPUT_DIR/badblocks.log
|
2016-12-15 18:06:32 -06:00
|
|
|
COUNT=0
|
|
|
|
TEST_PID=
|
2016-12-15 05:06:33 -06:00
|
|
|
wrapper-badblocks $DISK $SERIAL $JOBS &
|
2016-12-15 18:06:32 -06:00
|
|
|
sleep 1
|
|
|
|
RET=`jobs %+ | awk '/Exit [0-9]+/ {print $3}'`
|
|
|
|
if [[ -n $RET ]] ; then
|
|
|
|
echo -n "Exit $RET "
|
|
|
|
COUNT=$RET
|
|
|
|
fi
|
|
|
|
while (( $COUNT < $MAXWAIT )) ; do
|
|
|
|
COUNT=$(( COUNT + 1 ))
|
|
|
|
sleep 1
|
|
|
|
if [[ -f /run/$SERIAL.badblocks.pid ]] ; then
|
|
|
|
TEST_PID=`cat /run/$SERIAL.badblocks.pid`
|
|
|
|
echo " PID $TEST_PID"
|
2016-12-15 22:08:43 -06:00
|
|
|
echo " PID $TEST_PID" >> $OUTPUT_DIR/badblocks.log
|
2016-12-15 18:06:32 -06:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
echo -n '.'
|
|
|
|
done
|
|
|
|
if [[ -z $TEST_PID ]] ; then
|
|
|
|
echo "${RED}Process not running.${OFF}"
|
2016-12-15 22:08:43 -06:00
|
|
|
echo "${RED}Process not running.${OFF}" \
|
|
|
|
>> $OUTPUT_DIR/badblocks.log
|
2016-12-15 18:06:32 -06:00
|
|
|
fi
|
2016-12-15 05:06:33 -06:00
|
|
|
done
|
|
|
|
|
|
|
|
JOBS_WAITING=$JOBS
|
2016-12-15 22:08:43 -06:00
|
|
|
JOBS_OLD=0
|
|
|
|
COUNT=0
|
|
|
|
NOTICE_INTERVAL=60
|
2016-12-15 18:06:32 -06:00
|
|
|
while (( $JOBS_WAITING > 0 )) ; do
|
2016-12-15 05:06:33 -06:00
|
|
|
sleep 1
|
|
|
|
JOBS_WAITING=`jobs -r | wc -l`
|
2016-12-15 22:08:43 -06:00
|
|
|
JOBS_FINISHED=$(( JOBS - JOBS_WAITING ))
|
|
|
|
if (( $COUNT % $NOTICE_INTERVAL == 0 )) ; then
|
|
|
|
if [[ $JOBS_WAITING != $JOBS_OLD ]] ; then
|
|
|
|
echo "$JOBS_FINISHED jobs finished, $JOBS_WAITING jobs still running..."
|
|
|
|
JOBS_OLD=$JOBS_WAITING
|
|
|
|
fi
|
2016-12-15 05:06:33 -06:00
|
|
|
fi
|
2016-12-15 22:08:43 -06:00
|
|
|
COUNT=$(( COUNT + 1 ))
|
2016-12-14 22:57:46 -06:00
|
|
|
done
|
|
|
|
|
2016-12-15 22:08:43 -06:00
|
|
|
echo -n "END: " >> $OUTPUT_DIR/badblocks.log
|
|
|
|
date >> $OUTPUT_DIR/badblocks.log
|
|
|
|
echo >> $OUTPUT_DIR/badblocks.log
|
|
|
|
|
|
|
|
echo "=====> SUMMARY <====="
|
2016-12-16 08:02:21 -06:00
|
|
|
echo "SERVER|DISK|SERIAL|RESULT|COMMENT" > $OUTPUT_DIR/badblocks.csv
|
2016-12-15 22:08:43 -06:00
|
|
|
for DISK in `cat $OUTPUT_DIR/disk.lst \
|
|
|
|
| sed 's/#.*$//' \
|
|
|
|
| cut -d ':' -f 1`
|
|
|
|
do
|
|
|
|
SERIAL=`cat $OUTPUT_DIR/disk.lst \
|
|
|
|
| grep $DISK \
|
|
|
|
| cut -d ':' -f 2`
|
|
|
|
#echo "looking for $OUTPUT_DIR/disk/$SERIAL.badblocks.csv"
|
|
|
|
if [[ -f $OUTPUT_DIR/disk/$SERIAL.badblocks.result ]] ; then
|
|
|
|
cat $OUTPUT_DIR/disk/$SERIAL.badblocks.result
|
|
|
|
fi
|
|
|
|
if [[ -f $OUTPUT_DIR/disk/$SERIAL.badblocks.csv ]] ; then
|
|
|
|
cat $OUTPUT_DIR/disk/$SERIAL.badblocks.csv \
|
|
|
|
>> $OUTPUT_DIR/badblocks.csv
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
echo "=====> CSV SUMMARY <====="
|
|
|
|
cat $OUTPUT_DIR/badblocks.csv \
|
2016-12-16 08:02:21 -06:00
|
|
|
| sed "s/^\([^|]\+\)/${BLD}\1${OFF}/ ; s/OK/${GRN}OK${OFF}/ ; s/FAIL/${RED}FAIL${OFF}/ ; s/RESULT/${BLD}RESULT${OFF}/ " \
|
|
|
|
| sed 's/empty/W87152YGWGM/g'
|
2016-12-14 20:26:15 -06:00
|
|
|
|