hw-test/scripts/test-badblocks

129 lines
3.3 KiB
Bash
Executable file

#!/bin/bash
if [[ -z $OUTPUT_DIR ]] ; then
source scan-dmidecode
fi
source test-variables
SUMMARY=0
if [[ "$1" == "summary" ]] ; then
SUMMARY=plain
elif [[ "$1" == "csv" ]] ; then
SUMMARY=csv
else
scan-hdd # Always rescan
fi
if [[ "$1" == "force" ]] ; then
rm -f $OUTPUT_DIR/disk/*.badblocks.result
fi
MAXWAIT=9
JOBS=0
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 : " \
>> $OUTPUT_DIR/badblocks.log
COUNT=0
TEST_PID=
wrapper-badblocks $DISK $SERIAL $JOBS &
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"
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
fi
done
fi
JOBS_WAITING=$JOBS
JOBS_OLD=0
COUNT=0
NOTICE_INTERVAL=60
while (( $JOBS_WAITING > 0 )) ; do
sleep 1
JOBS_WAITING=`jobs -r | wc -l`
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
fi
COUNT=$(( COUNT + 1 ))
echo $JOBS_WAITING > /run/badblocks.waiting
done
rm -f /run/badblocks.waiting
echo -n "END: " >> $OUTPUT_DIR/badblocks.log
date >> $OUTPUT_DIR/badblocks.log
echo >> $OUTPUT_DIR/badblocks.log
#snapshot
mkdir -p $SNAPSHOT_D
cp -af $OUTPUT_DIR/* $SNAPSHOT_D/
if [[ $SUMMARY != 0 ]] ; then
if [[ $SUMMARY == plain ]] ; then
echo "=====> BADBLOCKS SUMMARY <====="
fi
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
echo "=====> BADBLOCKS CSV SUMMARY <====="
cat $OUTPUT_DIR/badblocks.csv \
| sed "s/^\([^|]\+\)/${BLD}\1${OFF}/ ; s/OK/$RES_OK/ ; s/FAIL/$RES_FAIL/ ; s/RESULT/$RES_ULT/ "
# | sed 's/empty/W87152YGWGM/g' # Serial number for debugging
fi