3

I got a simple MD5SUM script in the works. Its pretty much done except for the part that displays the progress (percent of the file that's been calculated to the user). I'm thinking of using a while loop w/ a dummy variable that checks if the MD5 has been calculated. The only problem is that md5sum (on linux) doesn't return any kind feedback, except when the actual md5sum has been calculated. So, its difficult to show the users how much of the file has been processed. Here's a copy of the script.

#!/bin/bash

#MD5 verification tool
#1st argument is file name of .iso, and the 2nd argument is the the MD5 hexsum.

echo Checking file $1 .....  
#calc md5 for file
SUM=`md5sum $1`
#insert while loop here?
#compare values
test $SUM = $2 && echo original || echo False 

#8cd98b693ce542b671edecaed48ab06d8c
# GNOME-64.iso

exit 0
gtgaxiola
  • 9,241
  • 5
  • 42
  • 64
LogicalConfusion
  • 263
  • 1
  • 4
  • 10
  • You won't be able to display an exact progress message so long as you rely on the `md5sum` command. Consider rolling your own `md5` hash program in a programming language like Python (using a hash library) if you want to display progress. – nneonneo Jan 29 '13 at 00:54
  • (That said, you can estimate progress very roughly by timing the command in a subshell and comparing the size of the file...but it's not going to be anywhere near accurate.) – nneonneo Jan 29 '13 at 00:54
  • Sure you will, you just measure the data being consumed rather than the internals of the md5summing. – that other guy Jan 29 '13 at 01:02

1 Answers1

14

Use pv, installable on all major distros. SUM=$(pv "$1" | md5sum) will show a pretty progress bar with throughput and everything, something like:

bash> pv /media/secondary/backups/2013_01_12/* | md5sum
10.2GB 0:01:32 [ 115MB/s] [====>                 ] 19% ETA 0:06:21
paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
that other guy
  • 116,971
  • 11
  • 170
  • 194
  • Wow, this is brilliant! Had to bring it down with apt on Debian but it's very handy. +1 and, if I had the power to accept it on Logical's behalf, I would :-) – paxdiablo Jan 29 '13 at 01:08
  • Thanks Pax! pv is really nice. I'm working on code so that just the stat bar is displayed w/out all the extra info. Just out of curiosity, do you know of a way to display a spinning *(asterisk) using bash while the file is being compared? – LogicalConfusion Jan 31 '13 at 22:29