script to create users on many servers

Hi all, working on script to create a user acct on all our servers.

for i in `cat $host_file`; do
ssh $i /usr/bin/sudo /usr/bin/mkuser id='bpadm' gecos='NetBackup Admin' 2>&1 >> $log
done

error i get is: 3004-692 Error changing "id" to "bpadm" : Value is invalid.

I have tried this in various ways, various quotes, tried on the cmd line on the target server. tried it without id= part.

I am just trying to create the user name and a value for gecos.
Server is AIX 5.X, shell is Korn.

thanks, dave

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

vi /tmp/pass
vi /tmp/shad

b. transfer the temp files to remote host

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 ...

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 ...

#! /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 ...

for remhost in `< /path/to/hostlist`
do
    scp -p /tmp/script $remhost:/tmp/script
    ssh $remhost "hostname; sudo /tmp/script"
done