#!/usr/bin/perl -w # ############################################################################ # # Name: md5checker.pl # Author: Pete Prodoehl # Author-Email: pete@rasterweb.net # # $Id: md5checker.pl,v 1.1 2005/03/16 17:46:18 pete Exp pete $ # ############################################################################ ############################################################################ # use modules use Digest::MD5; my $file = shift (@ARGV); my $srcdir = '/Users/pete/Incoming/'; my $desdir = '/Users/pete/Archive/'; my $source = $srcdir . $file; my $destin = $desdir . $file; if ( (-e($source)) and (-e($destin)) ) { my $sourcemd5 = &fingerprint($source); my $destinmd5 = &fingerprint($destin); my $sourcedupe = $source . '.dupe'; if ($sourcemd5 eq $destinmd5) { print "Files are the same!\n"; } else { print "Files are different!\n"; } } else { print "File specified does not exist in both directories...\n\n"; exit; } ################### # subs below here # ############################################################################ ############################################################################ # sub fingerprint sub fingerprint { my $bfil = $_[0]; open(BFIL, "<$bfil") or die "Can't open '$bfil': $!"; binmode(BFIL); $md5 = Digest::MD5->new; while () { $md5->add($_); } close(BFIL); return $md5->b64digest; } __END__ =head1 NAME md5checker.pl =head1 SYNOPSIS perl md5checker.pl foo.jpg =head1 DESCRIPTION This script assumes you have two directories and you want to check if two files with the same name in the two directories are the same or not. The date created and date modified may not work, so we do an md5sum on them to compare. =head1 AUTHOR Pete Prodoehl Epete@rasterweb.netE =head1 LICENSE This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. =cut