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!

Need help with copy and ownwership script

Status
Not open for further replies.

Planker

Technical User
Nov 27, 2006
2
US
I am looking for a script that i can copy a file a file to all 200 of my user's home dir. the ownership also needs to be modified to the user.

Thanks
 
And what have you tried so far ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I have not tried anything yet, I just found that for some reason when users are created, it is not creating the .profile in the users home dir and we just had a software upgrade installed that now requires the .profile to be in the home dir. I am very new to SCO and since this is a production environment I do not want to do anything to mess up the system. I have found two scripts that looks like they could be modified to work.


#!/bin/tcsh

foreach u ( /home/user /home/user1 /home/user2 /home/user3 )
foreach f ( /full/path/to/file /full/path/to/anotherfile )
echo $u
cp $f ${u}:$f
end
end

or

# /etc/passwd /usr/private/admin/passwd

Copy the password to a secure (700) area owned by root.

# vi /usr/private/admin/passwd

root:NqM5kgsU0o./6:0:0:root:/root:/bin/tcsh
bin:*:1:1:bin:/bin:
daemon:*:2:2:daemon:/sbin:
adm:*:3:4:adm:/var/adm:
lp:*:4:7:lp:/var/spool/lpd:
sync:*:5:0:sync:/sbin:/bin/sync
shutdown:*:6:0:shutdown:/sbin:/sbin/shutdown
postmaster:*:14:12:postmaster:/var/spool/mail:/bin/bash
nobody:*:65534:100:nobody:/dev/null:
ftp:*:404:1::/home/ftp:/bin/bash
guest:*:405:100:guest:/dev/null:/dev/null

Strip out all the system-related accounts that are not physical users.

# vi cphome

#! /bin/sh
cat /usr/private/admin/passwd | while read line
do
USER=`echo $line | awk -F":" '{print $1}'`
DIR=`echo $line | awk -F":" '{print $6}'`
cp $1 $DIR
chown $USER $DIR/$1
chmod 750 $DIR/$1
done
 
I believe you will need to create a text file containing all the usernames. Use this text file to feed your script.
This is how I'd do this, your situation may differ:

# cd /usr
# ls >ulist
(Now edit "ulist" to remove non-login names (such as "spool", "include", etc.) This is the hard part.

Create your sample .profile script, name it /tmp/profile.
Run these commands:
# cd /usr
# for i in `cat ulist`
# do
cp /tmp/profile /usr/$i/.profile
chown $i /usr/$i/.profile
chmod 600 /usr/$i/.profile
done
#
You can always test the script first by just including a single userid in the /usr/ulist file.
To fix your REAL issue (no .profile), take a look in the /usr/lib/mkuser/sh directory. This is the source location for the default $HOME directory stuff.


"Proof that there is intelligent life in Oregon. Well, Life anyway.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top