I had a problem to fix a few months back where by something like 1000 users had totally bricked their home folder permissions. Trying to propagate permissions from Workgroup Manager (it was a 10.4.11 server) kept hanging and would only fix home folders up to the letter “d.” It was at this point I was called in to write a script so a colleague could repair the permissions without running the risk of annihilating the home folders from the command line.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #!/usr/bin/env ruby # Name of group to apply new_group = "teachers" home_folders = Array.new sub_folders = %w(Pictures Documents Library Music Movies Sites Desktop) d = Dir.new(".") def do_cmd(*cmd) if $DEBUG cmd.each {|c| puts c} puts else cmd.each {|c| `#{c}`} end end d.each do |item| if File.directory?(item) home_folders << item end end home_folders -= %w(. ..) puts "Home folders found: ", home_folders.join(", "), "" home_folders.each do |item| do_cmd("sudo chown #{item}:#{new_group} #{item}", "sudo chmod 770 #{item}") sub_folders.each do |sub| do_cmd("sudo chown -R #{item}:#{new_group} #{item}/#{sub}", "sudo chmod -R 770 #{item}/#{sub}") end end if $DEBUG puts "You are working in debug mode. No changes have been made." end |
Any home folder will be owned by its respective user. The name of the folder will of course be the shortname, which made this a whole lot easier. Then it was just a case of picking a group and applying the changes to files and folders we knew were safe to change.







