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-20 04:43:12 -06:00
|
|
|
SUMMARY=0
|
|
|
|
if [[ "$1" == "summary" ]] ; then
|
|
|
|
SUMMARY=plain
|
|
|
|
elif [[ "$1" == "csv" ]] ; then
|
|
|
|
SUMMARY=csv
|
|
|
|
else
|
2016-12-15 22:08:43 -06:00
|
|
|
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-20 04:43:12 -06:00
|
|
|
if [[ $SUMMARY == 0 ]] ; then
|
|
|
|
echo -n "BEGIN: " >> $OUTPUT_DIR/badblocks.log
|
|
|
|
date >> $OUTPUT_DIR/badblocks.log
|
|
|
|
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`
|
|
|
|
if [[ -f $OUTPUT_DIR/disk/$SERIAL.badblocks.result ]] ; then
|
|
|
|
cat $OUTPUT_DIR/disk/$SERIAL.badblocks.result \
|
|
|
|
| sed 's/Process [0-9]\+/Test already done/'
|
|
|
|
cat $OUTPUT_DIR/disk/$SERIAL.badblocks.result \
|
|
|
|
| sed 's/Process [0-9]\+/Result found/' \
|
|
|
|
>> $OUTPUT_DIR/badblocks.log
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
JOBS=$(( JOBS + 1 ))
|
|
|
|
echo -n "Process $JOBS: Testing disk $DISK with badblocks ..."
|
|
|
|
echo -n "Process $JOBS : Disk $DISK : " \
|
2016-12-15 22:08:43 -06:00
|
|
|
>> $OUTPUT_DIR/badblocks.log
|
2016-12-20 04:43:12 -06:00
|
|
|
COUNT=0
|
|
|
|
TEST_PID=
|
|
|
|
wrapper-badblocks $DISK $SERIAL $JOBS &
|
2016-12-15 18:06:32 -06:00
|
|
|
sleep 1
|
2016-12-20 04:43:12 -06:00
|
|
|
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"
|
|
|
|
echo " PID $TEST_PID" >> $OUTPUT_DIR/badblocks.log
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
echo -n '.'
|
|
|
|
done
|
|
|
|
if [[ -z $TEST_PID ]] ; then
|
|
|
|
echo "${RED}Process not running.${OFF}"
|
|
|
|
echo "${RED}Process not running.${OFF}" \
|
|
|
|
>> $OUTPUT_DIR/badblocks.log
|
2016-12-15 18:06:32 -06:00
|
|
|
fi
|
|
|
|
done
|
2016-12-20 04:43:12 -06:00
|
|
|
fi
|
2016-12-15 05:06:33 -06:00
|
|
|
|
|
|
|
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-21 22:21:53 -06:00
|
|
|
echo $JOBS_WAITING > /run/badblocks.waiting
|
2016-12-14 22:57:46 -06:00
|
|
|
done
|
2016-12-21 22:21:53 -06:00
|
|
|
rm -f /run/badblocks.waiting
|
2016-12-14 22:57:46 -06:00
|
|
|
|
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
|
|
|
|
|
2016-12-20 05:48:03 -06:00
|
|
|
#snapshot
|
|
|
|
mkdir -p $SNAPSHOT_D
|
|
|
|
cp -af $OUTPUT_DIR/* $SNAPSHOT_D/
|
2016-12-20 04:43:12 -06:00
|
|
|
|
|
|
|
if [[ $SUMMARY != 0 ]] ; then
|
|
|
|
if [[ $SUMMARY == plain ]] ; then
|
2016-12-20 05:15:31 -06:00
|
|
|
echo "=====> BADBLOCKS SUMMARY <====="
|
2016-12-15 22:08:43 -06:00
|
|
|
fi
|
2016-12-20 04:43:12 -06:00
|
|
|
echo "SERVER|DISK|SERIAL|RESULT|COMMENT" > $OUTPUT_DIR/badblocks.csv
|
|
|
|
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 [[ $SUMMARY == plain ]] ; then
|
|
|
|
if [[ -f $OUTPUT_DIR/disk/$SERIAL.badblocks.result ]] ; then
|
|
|
|
cat $OUTPUT_DIR/disk/$SERIAL.badblocks.result
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [[ -f $OUTPUT_DIR/disk/$SERIAL.badblocks.csv ]] ; then
|
|
|
|
cat $OUTPUT_DIR/disk/$SERIAL.badblocks.csv \
|
|
|
|
>> $OUTPUT_DIR/badblocks.csv
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
if [[ $SUMMARY == csv ]] ; then
|
2016-12-20 05:15:31 -06:00
|
|
|
echo "=====> BADBLOCKS CSV SUMMARY <====="
|
2016-12-15 22:08:43 -06:00
|
|
|
cat $OUTPUT_DIR/badblocks.csv \
|
2016-12-22 23:35:03 -06:00
|
|
|
| sed "s/^\([^|]\+\)/${BLD}\1${OFF}/ ; s/OK/$RES_OK/ ; s/FAIL/$RES_FAIL/ ; s/RESULT/$RES_ULT/ "
|
2016-12-20 04:43:12 -06:00
|
|
|
# | sed 's/empty/W87152YGWGM/g' # Serial number for debugging
|
|
|
|
fi
|
2016-12-14 20:26:15 -06:00
|
|
|
|