Skip to content

Instantly share code, notes, and snippets.

@cvubrugier
Last active August 29, 2015 13:57
Show Gist options
  • Save cvubrugier/9901363 to your computer and use it in GitHub Desktop.
Save cvubrugier/9901363 to your computer and use it in GitHub Desktop.
Endlessly download a file with wget and verify that its content is unchanged.
#!/bin/sh
#
# Endlessly download a file with wget and verify that its content is unchanged.
# Usage: dlsum URL
#
error () {
echo "Data corruption detected! Here is the diff:"
mv $filename "${filename}.bad"
hexdump -C "${filename}.good" > "${filename}.good.hex"
hexdump -C "${filename}.bad" > "${filename}.bad.hex"
diff -Naur "${filename}.good" "${filename}.bad" > "${filename}.diff"
cat "${filename}.diff" | diff
exit 1
}
giga=$(expr 1024 \* 1024 \* 1024)
url=$1
[ -z "$url" ] && exit 1
filename=$(basename $url)
filesum="${filename}.md5"
wget -q $url -O $filename
sz=$(stat -c "%s" $filename)
md5sum $filename > $filesum
mv $filename "${filename}.good"
total=0
bound=$giga
for i in $(seq 1 100); do
wget -q $url -O $filename || break
md5sum -s -c $filesum || error
total=$(expr $total + $sz)
if [ $total -gt $bound ]; then
printf "%6d GB received\n" $(expr $total / $giga)
bound=$(expr $bound + $giga)
fi
rm -f $filename
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment