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 datasudo chmod -R +ai ittech allow list,add_file,search,delete,add_subdirectory,delete_child,readattr,writeattr,readextattr,writeextattr,readsecurity,file_inherit,directory_inherit dataRunning 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).
Run two commands based upon output of first
macintosh
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 $idoneIf you're happy with the sanity of the command, strip out the echos.