|
|
(view this code in a separate window)
#!/usr/bin/perl
#
# checkem.pl
#
# Simple perl file stats and md5 checksum printer.
#
# checkem.pl directory [directory ..]
#
# We suggest you send the output to a file and
# compare with previous runs using 'diff.'
#
# Or, better yet, use a real File Integrity
# Tool such as Aide.
#
# Copyright 2001, Bri Hatch
# Released under GPL
use MD5;
require 'find.pl';
$md5=new MD5;
@dirs = @ARGV;
for $dir ( @dirs ) { find($dir); }
sub wanted { push @files, $name; } # This subroutine is called
# for each file found
for $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$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";
}
|