how to compare permissions between two dirs
Chad Kellerman
sunckell at gmail.com
Mon Mar 22 12:24:31 UTC 2010
On Mon, Mar 22, 2010 at 7:33 AM, Aryeh M. Friedman <aryeh.friedman at gmail.com
> wrote:
> In switching to a new make file for a personal project I have run into the
> problem of under the old makefile everything works (web site) and under the
> new one it does not... when manually looking at the two dirs they appear
> identical in layout, sizes and perms (dir and file level) but I want to make
> sure... is there any way to compare two diff dirs and see if they only
> differ in date stamps? (note since there are several developers working on
> this project I need to compare even if the owners are diff)
> _______________________________________________
> freebsd-questions at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "
> freebsd-questions-unsubscribe at freebsd.org"
>
I have done this in the past....
You can write a script that writes the 'stats' that you want about each
directory to a file, then compare the two.
----------------------------<perl>------------------------
#!/usr/bin/perl
use strict;
use Fcntl ':mode';
use File::Find ();
use Digest::MD5;
use Getopt::Std;
$|++;
my %opts;
getopts('d:l:v', \%opts);
my $dirname = $opts{'d'} ? $opts{'d'} : die "Please provide a Snap Shot
directory\n";
my $log = $opts{'l'} ? $opts{'l'} : "/tmp/$0.$$";
my $verbose = $opts{'v'};
# for the convenience of &wanted calls, including -eval statements:
use vars qw/*name *dir *prune/;
*name = *File::Find::name;
*dir = *File::Find::dir;
*prune = *File::Find::prune;
sub wanted;
# Traverse desired filesystems
File::Find::find({wanted => \&wanted}, "$dirname");
exit;
sub wanted {
my ($dev,$ino,$mode,$nlink,$uid,$gid);
(($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
-f _
&& process( "$uid", "$gid", "$mode", "$name");
}
sub process {
my ($u, $g, $m, $n) = @_;
my $user = getpwuid($u);
my $group = getgrgid($g);
my $perms = sprintf "%04o", S_IMODE($m);
my $file = $n;
open FILE, $file or die "Can't open $file: $!\n";
binmode(FILE);
my $md5 = Digest::MD5->new->addfile(*FILE)->hexdigest, " $file\n";
close FILE;
print " $user $group $perms $md5 $n\n" if ($verbose);
open LOG, ">>$log" or die "Can't open log file: $!\n";
print LOG "$user $group $perms $md5 $n\n";
close LOG;
}
----------------------------------------</perl>----------------------
name the above script dirSnapShot.pl and run it like so: perl dirSnapShot
-d /dir1 then run it again perl dirSnapShot.pl -d /dir2
run a diff on the two log files in tmp to see the difference.
Chad
--
A grasshopper walks into a bar and the bartender says "Hey, we have a drink
named after you." And the grasshopper says "Really, You have a drink named
Murray?"
More information about the freebsd-questions
mailing list