Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 22 Mar 2010 08:02:43 -0400
From:      Chad Kellerman <sunckell@gmail.com>
To:        freebsd-questions@freebsd.org
Subject:   Re: how to compare permissions between two dirs
Message-ID:  <21bb29221003220502q29634386w3e84d432136ad0dc@mail.gmail.com>
In-Reply-To: <4BA75588.4090107@gmail.com>
References:  <4BA75588.4090107@gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Mar 22, 2010 at 7:33 AM, Aryeh M. Friedman <aryeh.friedman@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@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "
> freebsd-questions-unsubscribe@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?"



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?21bb29221003220502q29634386w3e84d432136ad0dc>