The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 09-25-2005
Just Ice's Avatar
Just Ice Just Ice is offline Forum Advisor  
Lights on, brain off.
  
 

Join Date: Mar 2005
Location: in front of my computer
Posts: 637
you might be better off appending an entry into the remote box's /etc/passwd file and then creating the home directory as required ...

a. create /etc/password and /etc/shadow strings for the user into temp files
Code:
vi /tmp/pass
vi /tmp/shad
b. transfer the temp files to remote host
Code:
cd /tmp
for remhost in `< /path/to/hostlist`
do
    tar cvfp - pass shad | ssh $remhost "cd /tmp; tar xvfp -"
done
c. append the strings and create home directory as required. put in the correct homedir path as required. please make sure to use ">>" or you'll clobber your files ...
Code:
for remhost in `< /path/to/hoslist`
do
    ssh $remhost "hostname; cat /tmp/pass >> /etc/passwd; cat /tmp/shad >> /etc/shadow; cd /home; mkdir -m 755 bpadm; chown bpadm bpadm; cd /tmp; rm pass shad"
done
the only catch here is your use of sudo ... you might want to put the commands i listed in item d in a script and then call sudo to run the script on the remote box ... assuming that you can put in the root password

the script ...
Code:
#! /usr/bin/ksh

[ -f /tmp/pass ] && cat /tmp/pass >> /etc/passwd
[ -f /tmp/shad ] && cat /tmp/shad >> /etc/shad
[ ! -d /home/bpadm ] && (cd /home; mkdir -m 755 bpadm; chown bpadm bpadm)
rm /tmp/pass /tmp/shad 2> /dev/null

exit 0
the job ...
Code:
for remhost in `< /path/to/hostlist`
do
    scp -p /tmp/script $remhost:/tmp/script
    ssh $remhost "hostname; sudo /tmp/script"
done