md5

Mario Hoerich lists at MHoerich.de
Wed Mar 30 07:55:16 PST 2005


# Matt Kosht:
> Is there a simple way to compare the md5 checksum of a file, to a file
> that contains possibly more than one md5 checksum entry in it?  Kind
> of like mdsum -c does?

Perfect job for a shellscript. :) 

    #!/bin/sh

    if [ -z "$2" ]; then
        echo "Usage: `basename $0` <file> <file with sums>" 1>&2
        exit
    fi    
    
    sum=`md5 "$1" | sed 's-^MD5 [^=]*= --'`
    cnt=`grep -c "$sum" "$2"`


    if [ $cnt -eq 0 ]; then
        echo "No match."
    else
        echo "Match."      
    fi


 HTH
Mario


More information about the freebsd-questions mailing list