Carl Lowenstein wrote:
On 11/21/06, Karl Cunningham <[EMAIL PROTECTED]> wrote:
Gus Wirth wrote:
> Is there a publicly searchable KPLUG mailing list archive anywhere?
> I'm looking for an old post by Carl Lowenstein that had a script for
> comparing an ISO image file to a CDROM/DVD to ensure it burned
> properly. I thought I saved it but I can no longer find it. My
> Thunderbird mail client doesn't search well enough for this.
>
> Or perhaps carl can send me the script?
>
> Gus
Here is what I use to burn and check the CD.

[the other] Karl


#!/bin/bash
ISOFILE=$1
[ -z "${ISOFILE}" ] && ISOFILE="/data/cdr/data.iso"
SPEED=$2
[ -z "${SPEED}" ] && SPEED="16"
cdrecord -v -fs=32m -dao -overburn speed=${SPEED} dev=/dev/hdc -data
${ISOFILE}
echo "Please stand by...  calculating md5sum..."
md5sum ${ISOFILE} /dev/cdrom

This is nice if you have an infinitely fast CPU.  Otherwise, you are
computing the MD5 sum of two large images, and then, it seems to me,
visually comparing them on two consecutive lines of screen output.

Why not just do a byte-by-byte compare cmp(1) of the two images.  Read
the two images in parallel, running at CDreader speed with no time out
for computing the MD5 sum.  Finishes early if there is an
early-detected error.

Things to note:  some CD drives don't know they have come to the end
of the image when reading, and continue for a few more blocks.  This
would change the comparison, whether MD5 or cmp.  So we want to
actually count the data as it is read, to stop at the end.

Not all images are ISO9660 even if we call them ".iso".  So the tool
/usr/bin/isosize won't always work for determining the image size.

#!/bin/sh
# $Id: isocmp,v 1.1 2006/04/03 21:19:09 cdl Exp $
# isocmp
#  compare image on burned {cd,dvd} with its source file
#   size=$(isosize -d 2048 $2)
#  don't use isosize, in case the image is not really iso9660

case $# in
       2) ;;
       *) echo "usage:  $0 /dev/cdrom /source/file.iso"; exit 2;;
esac

# a few sanity tests
if test ! -r $1
       then echo "can't read $1"; exit 2
fi
if test ! -r $2
       then echo "can't read $2"; exit 2
fi
if test ! -f $2
       then echo "$2 is not a file"; exit 2
fi

# compute size of file in 2kB blocks
size=$( dc -e "$(ls -l $2 | gawk '{print $5}') 2048/p")

# do the real work here, compare device file and source file byte by byte
dd if=$1 bs=2k count=$size 2>/dev/null | cmp -s $2 -

# report result
case $? in
       0) echo "good"; exit 0;;
       *) echo "bad"; exit 1;;
esac


   carl

Ah, this is it! Thanks for the repost. I now have it saved as a script with proper attribution. The trick I was looking for was the use of cmp to do the byte-by-byte comparison rather than doing the md5sum and comparing those. I probably would have used cut instead of gawk only because of 1) I don't really know gawk; and 2) cut is much smaller and simpler.

Also, if you were using the bash shell instead of a generic sh, you could probably also do the the math with the shell builtin rather than calling dc, but that would make the utility less portable for systems that don't have bash.

Gus

--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-newbie

Reply via email to