You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
2.0 KiB
50 lines
2.0 KiB
5 years ago
|
#!/bin/bash
|
||
|
|
||
|
SECTORS=$(parted ${1} unit s print | grep '^Disk /dev' | cut -d: -f2 | sed 's/ //g;s/s//g')
|
||
|
HDDSIZE=$((${SECTORS} * 512))
|
||
|
BLKSIZE=$((4 * 1024))
|
||
|
TBLOCKS=$((${HDDSIZE} / ${BLKSIZE}))
|
||
|
|
||
|
DESTROY=true
|
||
|
EXHAUST=12
|
||
|
echo Device ${1} is $(printf "%'d" ${HDDSIZE}) bytes
|
||
|
echo Testing $(printf "%'d" ${TBLOCKS}) blocks of $(printf "%'d\n" ${BLKSIZE}) bytes using 1/${EXHAUST} exhaustion.
|
||
|
POINTER=$((${RANDOM} % ${EXHAUST}))
|
||
|
|
||
|
BEGIN=$(date +%s)
|
||
|
|
||
|
until [ ${POINTER} = ${TBLOCKS} ]; do
|
||
|
# RUNTIME=$(($(date +%s) - ${BEGIN}))
|
||
|
# RTD=$((${RUNTIME} / 86400))
|
||
|
# RTH=$((${RUNTIME} % 86400 / 3600))
|
||
|
# RTM=$((${RUNTIME} % 3600 / 60))
|
||
|
# RTS=$((${RUNTIME} % 60))
|
||
|
|
||
|
# ETATIME=$(echo "scale=6;${RUNTIME}/(${POINTER}+1)*${TBLOCKS}+0.5" | bc | cut -d. -f1)
|
||
|
# [[ -z ${ETATIME} ]] && ETATIME=0
|
||
|
# ETD=$((${ETATIME} / 86400))
|
||
|
# ETH=$((${ETATIME} % 86400 / 3600))
|
||
|
# ETM=$((${ETATIME} % 3600 / 60))
|
||
|
# ETS=$((${ETATIME} % 60))
|
||
|
|
||
|
# ETRTIME=$((${ETATIME} - ${RUNTIME}))
|
||
|
# ERD=$((${ETRTIME} / 86400))
|
||
|
# ERH=$((${ETRTIME} % 86400 / 3600))
|
||
|
# ERM=$((${ETRTIME} % 3600 / 60))
|
||
|
# ERS=$((${ETRTIME} % 60))
|
||
|
|
||
|
# echo -n RUN $(printf "%02d:%02d:%02d:%02d\n" ${RTD} ${RTH} ${RTM} ${RTS})' '
|
||
|
# echo -n ETA $(printf "%02d:%02d:%02d:%02d\n" ${ETD} ${ETH} ${ETM} ${ETS})' '
|
||
|
# echo -n ETR $(printf "%02d:%02d:%02d:%02d\n" ${ERD} ${ERH} ${ERM} ${ERS})' '
|
||
|
|
||
|
echo -n BLK $(printf "%012d" ${POINTER} | sed 's/\(...\)\(...\)\(...\)\(...\)/\1,\2,\3,\4/g')...
|
||
|
|
||
|
RNDDATA="$(dd if=/dev/urandom bs=${BLKSIZE} count=1 status=none | base64)"; echo -n G
|
||
|
${DESTROY} || ( ORGDATA="$(dd if=${1} bs=${BLKSIZE} count=1 skip=${POINTER} status=none | base64)"; echo -n B )
|
||
|
echo "${RNDDATA}" | base64 --decode | dd of=${1} bs=${BLKSIZE} seek=${POINTER} status=none; sync; echo -n W
|
||
|
CHKDATA=$(dd if=${1} bs=${BLKSIZE} count=1 skip=${POINTER} status=none| base64); echo -n V
|
||
|
${DESTROY} || ( echo "${ORGDATA}" | base64 --decode | dd of=${1} bs=${BLKSIZE} seek=${POINTER} status=none; sync; echo -n R )
|
||
|
[[ "${CHKDATA}" == "${RNDDATA}" ]] && echo -ne "\r" || echo "...FAILED"
|
||
|
((POINTER+=${EXHAUST}))
|
||
|
done
|