Operating System - HP-UX
1753779 Members
7622 Online
108799 Solutions
New Discussion юеВ

Adding multiple users - trusted systems

 
SOLVED
Go to solution
sergiu1103
Occasional Contributor

Adding multiple users - trusted systems

Hello all,

My experience with HP-UX is not very vast, but I have done some searching before I decided to post this question here. I need to add multiple (quite a lot) on many new servers (trusted systems). Is there a way, or some existing scripts that can accomplish this? Thank you.

P.S. My scripting techniques are at basic level.
4 REPLIES 4
Paul Sperry
Honored Contributor

Re: Adding multiple users - trusted systems

Well I use this script when adding users to a new system. Bscically I use the /etc/passwd file to creat them an run this script on that file to create them

cat userinfo |while read line
do
USER=$(echo $line|awk '{FS=":";print $1}')
PASS=$(echo $line|awk '{FS=":";print $2}')
USERID=$(echo $line|awk '{FS=":";print $3}')
GID=$(echo $line|awk '{FS=":";print $4}')
INFO=$(echo $line|awk '{FS=":";print $5}')
HOME=$(echo $line|awk '{FS=":";print $6}')
SHELL=$(echo $line|awk '{FS=":";print $7}')
echo "Adding $USER"
useradd -u $USERID -g $GID -s $SHELL -c "$INFO" -o -d $HOME -m -k /etc/skel $USER
/usr/sam/lbin/usermod.sam -p`echo "$PASS"` $USER
done



where the file userinfo whitch is just /etc/passwd looks like this:


dclifton:QNlEo8shV4aAs:281:300:Dawn Clifton:/ifas/admin:/bin/ksh
dcomegys:AiBlSJmBOE8GQ:282:300:Debbie Comegys:/ifas/admin:/bin/ksh
ddeakin:J093/LdkPWe4.:283:300:Deborah Deakin:/ifas/admin:/bin/ksh
deborahv:d4J3aJqNPmXlY:284:300:Deborah Vessey:/ifas/admin:/bin/ksh
debraa:l3i8xgyOEBVpE:285:300:Debra Aragon:/ifas/admin:/bin/ksh
deel:m6FKASCYkdCMM:286:300:Delores Leschinsky:/ifas/admin:/bin/ksh
dellis:05/iQ.n/Yx1YU:287:300:Dean M Ellis:/ifas/admin:/bin/ksh
dfotsch:i5bZyPUeYJNkk:288:300:Dan Fotsch:/ifas/admin:/bin/ksh
dgeisert:x8EA/6uTHJdYs:289:300:Donna Geisert:/ifas/admin:/bin/ksh




Tim Nelson
Honored Contributor

Re: Adding multiple users - trusted systems

I do pretty much the same as Paul.

I have a script that prompts for usernames, group, home dir, etc.. then use that to create a script full of usermod commands.

if you have a list here is a simplistic approach.

list.txt contents:
jdoe John Doe
bdoe Bill Doe

script contents:
uid=1000
ok=
cat list.txt|while read uname fname lname
do
while [[ $ok != "ok" ]]
do
if grep ":$uid:" /etc/passwd > /dev/null
then
(( uid = uid + 1 ))
else
ok=ok
fi
done
useradd -u $uid -c "$fname $lname" -m -s /usr/bin/ksh $uname
ok=
done
#end-of-script

This is about as simple as it gets.
looks for next unused uid over 1000, creates username and comment provided by list.txt then uses default /usr/bin/ksh shell and creates default home directory.


VK2COT
Honored Contributor
Solution

Re: Adding multiple users - trusted systems

Hello,

You already got lot of useful advice and scripts.

For a different reason, I wrote a Perl
script that does the same on
AIX, HP-UX, Linux, Tru64, and Solaris.
Even if you do not need it, you
can at least check which commands are used
and compare how it is done in different
OSes :)

http://www.circlingcycle.com.au/Unix-sources/add-batch-Unix-accounts.pl.txt

Cheers,

VK2COT


VK2COT - Dusan Baljevic
sergiu1103
Occasional Contributor

Re: Adding multiple users - trusted systems

Thank you all for your quick and helpful replies. Dusan, your script looks like it required a lot of work, thank you for sharing. I think I will be using it, since I am dealing with multiple operating systems.