Changing User Dir Ownership
One nite while working on something late, i screwed up and accidently changed the ownership of all the user home dirs on the machine to being owned by me. Instead of berating myself all nite, i wrote 2 small scripts to change them back to the proper ownership. Bascially what i want to do is change the ownership of each dir in /usr/home to the name of the dir. In other words, I want the dir /usr/home/ed owned by ed. First I need to list all the dirs in /usr/home. BTW: both scripts for this resided in /usr/home for this. Modify to suit your needs. The first script was like this: #!/bin/sh /bin/ls | /usr/bin/xargs -n1 /usr/home/script2.sh
Now the script2.sh consisted of this: #!/bin/sh NAME=$1 /usr/sbin/chown -R $NAME $NAME
The first script did an ls but then fed each single dir name to script2.sh one at a time. The second script took took the output from the first script and used it as teh arguments for the chown. Thus together the scripts read each dir/file name in /usr/home and then chown the dir to the username that is the same as the dir name. I have actually used this about 5 times now to save me from quite a bit of boring work fixing typos/mistakes. I was working on a way to do it all in one file, but couldn't get it to properly feed the dir name twice to the chown command. I might play with this more later and try to get that done, but for now it works and functions just fine for my uses.
|