Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm new to unix commands but have a need. I have a mixed Win/Mac environment where I use Win AD for user accounts and the Mac as the file storage.

There is a command on Mac that automatically creates the home folders for users and sets appropriate permissions 'createhomedir -s' in my situation. The output of this command is:

creating home directories for (cloud.mc.net.mackillop)
created (/Network/Servers/cloud.mc.net.mackillop/data/18goodki/files)
created (/Network/Servers/cloud.mc.net.mackillop/data/18langre/files)
created (/Network/Servers/cloud.mc.net.mackillop/data/16gibsga/files)
created (/Network/Servers/cloud.mc.net.mackillop/data/17gibssa/files)
created (/Network/Servers/cloud.mc.net.mackillop/data/99bowmam/files)
created (/Network/Servers/cloud.mc.net.mackillop/data/99newtal/files)
created (/Network/Servers/cloud.mc.net.mackillop/data/99daypa/files)

What I need to then also do is set additional permissions on these newly created home folders, to provide myself with read/write access as well as _www (Apache web host) as we use OwnCloud.org to supply web based cloud access to users files.

These are the two commands I run to achieve this:

sudo chmod -R +ai "_www allow list,add_file,search,delete,add_subdirectory,delete_child,readattr,writeattr,readextattr,writeextattr,readsecurity,file_inherit,directory_inherit" data

sudo chmod -R +ai "ittech allow list,add_file,search,delete,add_subdirectory,delete_child,readattr,writeattr,readextattr,writeextattr,readsecurity,file_inherit,directory_inherit" data

Running these two commands over the entire 'data' folder of all users and subfolders takes ages (973 user accounts!) and really slows down the server. What I would like to to is only run these two commands on newly created users from the first command to greatly reduce time and overhead.

I've been reading on grep, awk etc but not really sure how to achieve this.

So basically I want to get createhomedir -s to run, then extract each username from the output of this command, then use these usernames to run the two chmods in place of the 'data' folder (/data/%USERNAME% instead).

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Easy enough ... just wrap it in the following (caveat: we're assuming that the create bit is successful, and that the output of createhomedir is on STDOUT rather than STDERR):

for i in $(createhomedir -s | grep -o 'data/[^\/]*' )
do
  echo sudo chmod -R +ai "_www allow list,add_file,search,delete,add_subdirectory,delete_child,readattr,writeattr,readextattr,writeextattr,readsecurity,file_inherit,directory_inherit"  $i
  echo sudo chmod -R +ai "ittech allow list,add_file,search,delete,add_subdirectory,delete_child,readattr,writeattr,readextattr,writeextattr,readsecurity,file_inherit,directory_inherit" $i
done

If you're happy with the sanity of the command, strip out the "echo"s.

share|improve this answer
2  
there's an extra single quote in your example. Also if you remove the leading slash from your grep command, the resulting path will match the OP's usage (relative path to 'data') ... createhomedir -s | grep -o 'data/[^\/]*'. –  Eli Heady Apr 5 '13 at 0:28
    
Thx ELi, patched up. –  tink Apr 5 '13 at 1:32
    
Thanks so much tink and Eli, it works! Even better I understand it! :) –  user36541 Apr 5 '13 at 9:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.