Recently I needed to check some md5 hashes of some files on NetBSD. I started toying with awk, and just glanced on a cksum(1) man page. There was the "-c" option staring at me, which is being used to check md5 hashes from a file. The option was not actually available until NetBSD 4.0. Reading further on the net, I discovered that FreeBSD does not have that option (OpenBSD cksum has the "-c" option). One could get the option by installing md5sum (from
sysutils/coreutils), but it is not in base system. To cut the long story short, here is the code that someone might find useful:
Code:
#!/bin/sh
# awk code for: cksum -c MD5
md5 "$1" | \
awk '
NR==FNR{
a[$2]=$4
next
}
($2 in a){
if(a[$2] == $4)
print "OK: " $2
else
print "ERROR: " $2
}' - "$2"
Example:
Code:
$ md5 file.iso >CKSUM.MD5
$ cat CKSUM.MD5
MD5 (file.iso) = b76561047748615d9a6a40da795fac3d
$ ./md5_check.sh file.iso
OK: (file.iso)
$
Script could be useful for those that don't have
gmd5sum (i.e. GNU md5) installed, and they want to check the md5 hash of a FreeBSD iso file they just downloaded.