|
(view this code in a separate window) #!/usr/bin/perl # # checkem.pl # # Lame file integrity tool that uses MD5 # checksums. # # Copyright 2002, Bri Hatch # # Released under the GPL. See COPYING file # for more information. use MD5; require 'find.pl'; $md5 = new MD5; @dirs = @ARGV; foreach $dir ( @dirs ) { find($dir); } sub wanted { push @files, $name; } # This subroutine is called # for each file found foreach $name ( sort @files ) { ($uid,$gid) = (stat $name)[4,5]; $stat = sprintf "%0o", (stat _)[2]; unless ( -f $name ) { printf "$stat\t$uid $gid\t\t\t\t\t\t$name\n"; next; } # abort here if not a 'plain' file # Do a checksum $md5->reset(); open FILE, $name or print(STDERR "Can't open file $name\n"), next; $md5->addfile(FILE); close FILE; $checksum = $md5->hexdigest(); printf "$stat\t$uid $gid $checksum\t$name\n"; }
|