Skip to content

Instantly share code, notes, and snippets.

@jdmichaud
Created August 11, 2018 21:19
Show Gist options
  • Save jdmichaud/4214ee0a5d19e98fe7a08448bdf67e51 to your computer and use it in GitHub Desktop.
Save jdmichaud/4214ee0a5d19e98fe7a08448bdf67e51 to your computer and use it in GitHub Desktop.
Test USB drive capacity
#!/bin/bash
if [[ $# -ne 1 ]]
then
echo "To test for 16G capacity"
echo "usage: testcap.sh 16"
exit 1
fi
echo "checking for capacity ${1}G"
for i in `seq 1 1 $1`
do
cat /dev/urandom | head -c 1G > $i
md5=$(md5sum $i | cut -c 1-32)
mv $i $md5
echo $md5 >> index
pc=$(echo "scale=1; $i/$1*100" | bc)
echo "${pc}%"
done
count=0
for entry in $(cat index)
do
# check file exists
if [[ ! -f $entry ]]
then
echo "file $entry does not exists"
elif [[ $(md5sum $entry) = $entry ]]
then
echo "bad md5sum for file $entry"
else
count=$((count+1))
fi
done
echo "real capacity ${count}G"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment