Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2024-04-25 02:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found