[K12OSN] chown script help needed (word of caution)
Les Mikesell
les at futuresource.com
Sun Sep 4 17:49:21 UTC 2005
On Sun, 2005-09-04 at 11:38, John Baillie wrote:
> >I'm in sort of a bind and I need someone to help me with a chown
> >script. Because of some craziness with webmin and some idiocy in need
> >a script that will do this: for UID including and over 531 I'd like
> >to chown -R users home folders to their own UID:GID. It looked as if
> >webmin would do this for me but unfortunately not.
Do you really have users with uid < 531 with home directories
that don't belong to the user with the same name?
> >
> Here's a little script that will do the magic.
>
> #!/bin/bash
>
> for i in `ls /home/`;
> do
> chown -R $i:$i /home/$i
> echo chowning $i to $i
>
> done
>
> Word of caution:
>
> Using the webmin add user bulk script it is possible to name home dirs
> with a space and a slash at the tail
> for instance /home/jsmith /
> this can distroy your machine by running the reset-all-desktops script
> you end up chowning everything under / to jsmith:jsmith
I don't think you can physically embed a / in a file or directory
name. You are adding them as part of the way you expand the
names. I'd do it this way instead:
cd /home
for i in *
do
chown -R $i:$i $i
done
This will simply fail if one of the names contains spaces.
If you really don't want to do this to all the directories
under /home, you can generate the list some other way.
For example you could copy the /etc/passwd file, delete
the range you don't want, then (in vi) :%s/:.*// to
leave only the names. If you save that in a file you
can change the 'for i in *' line above to
for i in `cat file`
to iterate over the list you want.
--
Les Mikesell
les at futuresource.com
More information about the K12OSN
mailing list