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!

Adding a file to the home directory of users 2

Status
Not open for further replies.

mohmin

Technical User
Jun 13, 2005
38
US
Guys,
I need to add a particular file to the home directories of each user on AIX server.

Is there a quicker way doing this rather than going to the home directory of each user and copying?


Will appreciate,
Mohmin.
 
something like

for I in `ls -1 /home`;do
cp <file> /home/$I
done


might work. you could filter for directories where you don't want to copy this file, like lost+found, etc... or just go behind yourself and remove them by hand.
 
Hey Breslau,
I need to add the file to the home directories of all users belonging to a partciluar group only, how would this be accomplished?

thanks,
Moh.
 
for I in `ls -l /home|grep group|awk '{print $NF}'`;do
cp <file> /home/$I
done
 
if you want to match on a specific group and not just the one listed on the user's home dir (which is what i think you're asking for) then this might work:

for I in `ls -1 /home |awk '{print $1}'`;do
if [ "$I" != "lost+found" ]
then
for J in `groups $I`;do
if [ "$J" = "groupname" ]
then
cp <file> /home/$I;
fi
done
fi
done

while not foolproof, it at least skips the lost+found directory, if your home dirs are in a filesystem of their own. you could tweak something like this and place it in a script if the file copy task is something you do on a regular basis.

anyway, hope it helps...
 
Why not identify the home directories from /etc/passwd.
Code:
for i in $(cat userlist)
do
  cp $file $(egrep ^${i}: /etc/passwd | cut -f 6 -d :)
done
How you create userlist is another matter. If you're using AIX you can use lsgroup or use groups as per Breslau's suggestion

Columb Healy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top