Created
January 23, 2015 10:18
-
-
Save tlrobinson/a9551de628a9621af8d2 to your computer and use it in GitHub Desktop.
OS X tool (easily portable to other *nixes) that writes random data to a disk (e.x. SD card) and reads it back, comparing hashes of the data. Use with caution.
This file contains 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 | |
set -eu | |
disk_file="$1" | |
bytes="$(diskutil info "$disk_file" | grep -Eo '\(\d+ Bytes\)' | grep -Eo '\d+')" | |
block_size="$((1024 * 1024))" | |
blocks="$((bytes / block_size))" | |
read -p "Are you sure you want to unmount and overwrite $disk_file? " -n 1 -r; echo | |
if [[ $REPLY =~ ^[Yy]$ ]]; then | |
diskutil unmountDisk "$disk_file" | |
dd bs="1m" count="$blocks" if="/dev/urandom" 2>/dev/null | tee >(md5 1>original.md5) | dd of="$disk_file" | |
dd bs="1m" count="$blocks" if="$disk_file" | md5 >result.md5 | |
cat original.md5 result.md5 | |
rm original.md5 result.md5 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment