in reply to Re: Checking permissions in multiple directories
in thread Checking permissions in multiple directories

I need to check the entire tree, not just the directories, but the files inside the directories. Also, if a file doesn't exist i need it to tell me it doesnt exist.
  • Comment on RE: Re: Checking permissions in multiple directories

Replies are listed 'Best First'.
RE: RE: Re: Checking permissions in multiple directories
by Corion (Patriarch) on Jun 04, 2000 at 14:11 UTC

    File::Find already descends down through all subdirectories, sorry if I didn't mention that.

    But it really seems to me as if a tool such as rsync or a simpler solution using tar cfz transfer.tgz would do what you want in a much better way, since rsync can keep two directory branches synchronized in all ways without transferring all files and tar works more or less like cp. Please either restate your problem or think about using a readymade tool.

    The necessary modifications for my above script to tell you if a file is missing on machine B would be in the routine checkpermissions() :

    sub checkpermissions { my( $directory ) = @_; my ( $targetdir = $directory ) =~ s!^$sourcedir!$targetdir!; # now we check first of the item in $targetdir exists : if (-f $targetdir || -d $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 permissi +ons for $targetdir : $!\n"; }; } else { # I assume you don't have links or other stuff. # If you have symlinks etc., use rsync or tar # I cheat and call cp for copying all stuff recursively system "cp", "-R", "$directory", "$targetdir"; }; };
    Please think again about whether you really want to use Perl for this problem.

    When all you have is a hammer,
    every problem looks like a nail.

      I tired using the stat function, but the when I do a $temp = $stats2; i get a number like 33261 then the chmod craps out. Am I doing something wrong?

        Since you aren't even telling, what goes wrong, I can't help you here. Maybe you don't have the right permissions on the target machine or the target directory...