http://qs321.pair.com?node_id=16205


in reply to Checking permissions in multiple directories

If I understood your question right, you have two machines, A and B, and have a directory on machine A of which you want to clone the permissions onto a directory with the same contents on machine B.

Personally, I would think that a program such as rsync would do what you want, as rsync also synchronizes the files themselves, or, if your setup is even simpler, even tar would be enough.

There is also the question of how the data will be transferred between the two directories and the question of the operating system. If you are using a UNIX-like operating system, you have to make sure that the UIDs on both machines are the same.

If you can somehow mount both directories on one machine, cloning the permissions is relatively simple done by using readdir() or File::Find (note that this is untested):

$sourcedir = "/mnt/dev/"; # adapt this $targetdir = "/mnt/test/"; # adapt this use File::Find; find( \&check, $sourcedir ); sub check { my( $name ); $name = File::Find::dir . "/" . $_; &checkpermissions( $name ); }; sub checkpermissions { my( $directory ) = @_; my ( $targetdir = $directory ) =~ s!^$sourcedir!$targetdir!; my ($perm_s, $perm_t); my @statresults; # This could be more optimized, but ... @statresults = stat( $directory ); $perm_s = @statresults[2]; @statresults = stat( $targetdir ); $perm_t = @statresults[2]; if ($perm_s != $perm_t ) { print "$targetdir has wrong permissions."; chmod $perm_s, $targetdir or die "Couldn't update the permission +s for $targetdir : $!\n"; }; };