Created
November 2, 2017 06:44
-
-
Save andyfangdz/7958cbaef6aa8ede5e1d97cdc9ec9116 to your computer and use it in GitHub Desktop.
FS consistency test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
RED='\033[0;31m' | |
GREEN='\033[0;32m' | |
NC='\033[0m' | |
filename='sha256.txt' | |
i=0 | |
matches=0 | |
mismatches=0 | |
missing=0 | |
while read p; do | |
if [ ! -f ${i}.test ]; then | |
echo -e "${RED}$i.test missing${NC}" | |
missing=$((missing + 1)) | |
i=$((i + 1)) | |
continue | |
fi | |
output=`sha256sum ${i}.test` | |
if [ "$output" == "$p" ] | |
then | |
echo -e "${GREEN}$i.test match${NC}" | |
matches=$((matches + 1)) | |
else | |
echo -e "${RED}$i.test mismatch${NC}" | |
mismatches=$((mismatches + 1)) | |
fi | |
i=$((i + 1)) | |
done < $filename | |
echo -e "${GREEN}${matches}${NC} matches, ${RED}${mismatches}${NC} mismatches, ${RED}${missing}${NC} missing." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
echo "Testing reliability on $1 files" | |
for ((i=0;i<$1;i++)) | |
do | |
echo "Generating file $i..." | |
dd if=/dev/urandom of="${i}.test" bs=1k count=$2 | |
done | |
if [ -f sha256.txt ]; then | |
rm sha256.txt | |
fi | |
for ((i=0;i<$1;i++)) | |
do | |
sha256sum "${i}.test" >> sha256.txt | |
done | |
echo "==== Begin SHA256 output of files ====" | |
cat sha256.txt | |
echo "==== End SHA256 output of files ====" | |
echo "Copy \`sha256.txt' to a secure location." | |
read -n 1 -s -r -p "Press any key to continue" | |
echo "Copying files. Pull the plug now!" | |
cp *.test $3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment