Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- # High speed recursive permission changer
- $pwd = `pwd`;
- $pwd = s/ /\\ /g;
- $dmode = @ARGV[0];
- $fmode = @ARGV[1];
- $user = @ARGV[2];
- $group = @ARGV[3];
- $verbose = @ARGV[4];
- if (!$fmode || !$dmode) {
- print "Usage: perms.pl dirmode filemode [user] [group] [-v]\n";
- exit();
- }
- $files = `find $pwd`;
- @files = split("\n",$files);
- $i = 0;
- $j = 0;
- if ($user && $group) {
- ($login,$pass,$uid,$gid) = getpwnam($user);
- my $username = getpwuid( $< );
- if ($username ne "root") {
- die("Changing owner:group requires root.");
- }
- $gid = getgrnam($group);
- if (!$uid) {
- print "User \"".$user."\" does not exist!\n";
- exit();
- }
- if (!$gid) {
- print "Group \"".$group."\" does not exist!\n";
- exit();
- }
- } else {
- $verbose = @ARGV[2];
- }
- foreach $file (@files) {
- if (-d $file) {
- if ($verbose) {
- print "Setting permissions (".$dmode.", ".$uid.":".$gid.") on $file...\n";
- }
- chmod oct($dmode), $file;
- if ($uid && $gid) {
- chown $uid, $gid, $file;
- }
- }
- else {
- if ($verbose) {
- print "Setting permissions (".$fmode.", ".$gid.":".$uid.") on $file...\n";
- }
- chmod oct($fmode), $file;
- if ($uid && $gid) {
- chown $uid, $gid, $file;
- }
- }
- if (!$verbose) {
- $i++;
- print "Set permissions on ".$i." objects...";
- print "\r";
- }
- }
- if (!$verbose) {
- print "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement