#!/bin/bash if [[ -z $OUTPUT_DIR ]] ; then source scan-dmidecode fi source test-variables if [[ "$1" != "skip-scan" ]] ; then scan-hdd # Always rescan fi if [[ "$1" == "force" ]] ; then rm -f $OUTPUT_DIR/disk/*.badblocks.result fi MAXWAIT=9 JOBS=0 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 complete/' 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 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 )) done echo -n "END: " >> $OUTPUT_DIR/badblocks.log date >> $OUTPUT_DIR/badblocks.log echo >> $OUTPUT_DIR/badblocks.log echo "=====> SUMMARY <=====" 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 [[ -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 \ | 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'