Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

changing user owners by a script

Status
Not open for further replies.

vti

Technical User
Feb 26, 2001
189
TR
Hi all,

I got nearly 2000 users on my system and some reason their home_path owners changed as root.I want to change their home_path owners by a script.They has to have their own owners name and datau as group.

I got two output one of them like ;

/usr/users/user1
/usr/users/user2
/usr/users/user3

and other file is like ;

user1
user2
user3

All i want to do is

chown user1:datau /usr/users/user1

I have tried with


for i in `cat userspath|awk ' {print $1}'`
do
for e in `cat owners|awk ' {print $1}'`
do
chown $e:datau $i
read a
done
done

But didn't work as i want.And under the /usr/users folder has also lot's of sub folders but i have all paths are in "userpath" file.

Thanks for any help.
 
Hi,

Maybe something more simple like:

cd /usr/users
for i in *; do
chown -R $i:datau $i
done
 
if you have a file with all users that you want to change the HOME_DIR's rights...

try the script:
############ use ksh or bash
$ for i in `cat users_file`
do
chown -R ${i}:datau ~${i}
done
############

__
___
 
hi
Thanks for help but it's not working cause my user_path_file has path like ;

/usr/users/user1
/usr/users/user2

And when i run your script it returns error

chown: unknown username /usr/users/user1
chown: unknown username /usr/users/user2

So i need to use this file as path and cut user name as owner.but how?




 
In your first post you seemed to indicate that you already had a file with just the user names in it? If you haven't, do the following to create one:

cat /etc/passwd | cut -f1 -d':' > usernames

Edit this to take out those users you don't want included (eg root) and then use it as your source.

HTH.
 
It works
Thanks a lot
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top