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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scripting, having a fiddle !

Status
Not open for further replies.

bennotech

Technical User
Aug 7, 2002
64
GB
Hello All,
Been fiddling on my test box and all of the users home directories are now owned by root (don't ask !!)
Would like to correct the ownership and tried this :

1. Created a file with a line for each user:

benno:benno benno
other:eek:ther other
etc
etc

2. for I in `cat said file`
do
chown $I
done

This didn't work because the cat command lists the output of the file as:

benno:benno
benno
other:eek:ther
other

(for I in `cat said file`
do
echo $I
done)

When I cat the file from the command line (cat filename) the output is benno:benno benno
other:eek:ther other

Any ideas ??

cheers
Benno





...it really does get worse than this !!
 
last bit should read:

benno:benno benno
other:eek:ther other

...it really does get worse than this !!
 
for i in `awk -F: '{print $1}' /etc/passwd` ; do
chown -R $i:staff /home/*
done

You'll have to muck about with group to get adm / root / ... right

Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
Now that's carp. Doesn't take into account dir owner

chown -R $i:staff /home/$i


Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
thanks Mike but what about groups, that would change everything to staff ?

...it really does get worse than this !!
 
Instead of [tt]for..in[/tt], try:
Code:
cat said_file | while read usrgrp user
do
chown $usrgrp /home/$user
done

- Rod




IBM Certified Advanced Technical Expert pSeries and AIX 5L
CompTIA Linux+
CompTIA Security+

Wish you could view posts with a fixed font? Got Firefox & Greasemonkey? Give yourself the option.
 
It would change all the groups to staff, but what would you want them to be?

Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
...ora... (Sap DBA) will need sapsys for example. I guess it would be easier to restore /home but not as much fun !!

...it really does get worse than this !!
 
thanks Rod, simple when you know how,
Benno

...it really does get worse than this !!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top