LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   Concurrently Running dd and md5sum Commands (https://www.linuxquestions.org/questions/slackware-14/concurrently-running-dd-and-md5sum-commands-716654/)

Woodsman 04-03-2009 03:26 PM

Concurrently Running dd and md5sum Commands
 
Is there a way to merge the following two commands?

Code:

dd if=$DEVNODE of=$TMPDIR/$FILENAME bs=2048 conv=sync,notrunc

MD5SUMDISK="`dd if=$DEVNODE | md5sum | awk '{print $1}'`"

My goal is to run the dd command only once yet concurrently retrieve the md5sum. The disk md5sum is then later compared to the disk image md5sum.

Running dd twice is doable but time consuming.

P.S. I 'm not trying to concatentate the two commands on one line using the '&&' parameter. I'm trying to run dd only once.

Thanks again.

H_TeXMeX_H 04-03-2009 03:37 PM

See here:
http://www.linuxquestions.org/questi...8/#post3458795

Another option is the check program, it's also in the above thread.

GazL 04-03-2009 03:54 PM

Hmm, the problem you'll have is that should your input file not be an exact multiple of your blocksize, the conv=sync will pad the end of output file as it passes through dd. This will mean that your md5sum will differ from a md5sum of the input (the two files will be of different sizes).

If you don't need the conv=sync then you should be able generate a md5sum and do the dd at the same time with something along the lines of:
Code:

md5sum <(dd if=infile | tee -f ouputfile)
Note: I've not got access to my linux box at the moment so I'm unable to verify if this is valid or not, but I think it'll work.

Woodsman 04-03-2009 05:06 PM

Quote:

md5sum <(dd if=infile | tee -f outputfile)
The tee command. Sounds useful!

The basic command seems to succeed without the -f option --- I could find no -f option in the tee man page and I received an error message with -f.

Seems to work but is the md5sum output that of infile or outputfile? The md5sum output is from /dev/fd/63.

Similarly:

MD5SUMDISK="`dd if=$DEVNODE | tee $FILENAME | md5sum | awk '{print $1}'`"

Because tee splits the output, I don't know which MD5SUM is being reported.

:scratch: :)

GazL 04-03-2009 05:15 PM

Quote:

Originally Posted by Woodsman (Post 3497764)
The tee command. Sounds useful!

The basic command seems to succeed without the -f option --- I could find no -f option in the tee man page and I received an error message with -f.

Seems to work but is the md5sum output that of infile or outputfile? The md5sum output is from /dev/fd/63. :scratch:

In that command it would be the md5sum of the stdout output of the tee, which should be the same as the stdout of the dd. though without the conv=sync it should be identical to the input.

And yes, you're quite right, It appears I made the -f up. Been a while since I've used tee. Sorry 'bout that.

edit: oh, and the <( ) shell syntax generates a fifo/named pipe, which explains the wierd /dev/fd name. You'll need to code your script to replace that with the name of the output file on the tee if you store the output of the md5sum for later use.


All times are GMT -5. The time now is 03:33 PM.