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).
createhomedir -s | grep -o 'data/[^\/]*'
. – Eli Heady Apr 05 '13 at 00:28