[K12OSN] chown script help needed (word of caution)

Eric Harrison eharrison at mail.mesd.k12.or.us
Tue Sep 20 04:51:10 UTC 2005


On Wed, 14 Sep 2005, Michael C Wescott wrote:

> On Tue, 2005-09-13 at 09:00 -0700, Quentin Hartman wrote:
>> A little one-liner I've used in the past to fix permissions only on
>> "real" user directories and leave other stuff I tend to keep in /home
>> alone is:
>>
>> for i in `cat /etc/passwd | awk -F: '$3 > 500 {print $1}'`; do chown -R
>> $i:$i $i; done
>
> Gratuitous cat abuse :-)
>
> version 0.2:
>
> for i in `awk -F: '$3 > 500 {print $1}' /etc/passwd`; do chown -R $i:$i
> $i; done
>
> version 0.3:
>
> awk -F: '$3>500 {print $3, $4, $6}' /etc/passwd | while read u g h
> do
>   chown -R $u:$g "$h"
> done
>
> This last one avoids the assumption that the primary group name is
> the same as the username (though that will almost always be true). It
> uses the name of the home directory directly from the password file
> rather than trying to constructing it on the fly (it also works with
> home dirs with spaces in the name).
>
> I also suggest running pwck first to check the consistency of the
> password file.

version 0.4:

   getent passwd | awk -F: '$3>500 {print $3, $4, $6}' | while read u g h
   do
      chown -R $u:$g "$h"
   done


"cat /etc/passwd" assumes that your users are in /etc/passwd. If you 
your users in LDAP, AD, radius, etc, etc, you can't grep for them
in /etc/passwd...

"getent passwd" will output what you would expect to find in /etc/passwd,
even though the users may be in LDAP, WinBind, /etc/passwod, and/or any
other possible way the system may do authentication/authorization ;-)

-Eric




More information about the K12OSN mailing list