DaemonForums  

Go Back   DaemonForums > Miscellaneous > Guides

Guides All Guides and HOWTO's.

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1   (View Single Post)  
Old 15th January 2010
s0xxx's Avatar
s0xxx s0xxx is offline
Package Pilot
 
Join Date: May 2008
Posts: 192
Default Script to check md5 hash on FreeBSD

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.
__________________
The best way to learn UNIX is to play with it, and the harder you play, the more you learn.
If you play hard enough, you'll break something for sure, and having to fix a badly broken system is arguably the fastest way of all to learn. -Michael Lucas, AbsoluteBSD

Last edited by s0xxx; 17th January 2010 at 12:10 AM.
Reply With Quote
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
please check my pf.conf gosha OpenBSD Security 10 30th January 2009 12:32 AM
"free" command/perl script for freebsd unixdude FreeBSD General 0 17th November 2008 09:23 PM
Best way to check if freebsd server is running a nameserver service/daemon Yuka FreeBSD General 7 6th November 2008 01:26 AM
check for badblocks ccc FreeBSD General 5 30th October 2008 07:00 PM
relayd (and hoststated) give syntax error for 'check script' gwl OpenBSD Security 2 2nd May 2008 04:53 PM


All times are GMT. The time now is 02:27 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick