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"; }; };


In reply to Re: Checking permissions in multiple directories by Corion
in thread Checking permissions in multiple directories by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.