1845904 Members
4706 Online
110250 Solutions
New Discussion

Useradd script

 
Abhijeet_3
Frequent Advisor

Useradd script

I need to craete more than 600 users.

Is any script available for it.
I need to specify user id as its Emp id. & as comment is First name and Last name.

Password will be this loginname .

Regards
Abhijeet
6 REPLIES 6
harry d brown jr
Honored Contributor

Re: Useradd script

If you have employee ID's less than 1000, then I suggest you add 100000 to the employee id's so that they don't conflict with SYSTEM id's.

As for a script, you can use vi to build one rather quickly, provided you have the list of employee names and ID's available. The hardest part will be creating unique USER NAMES.

live free or die
harry d brown jr
Live Free or Die
Muthukumar_5
Honored Contributor

Re: Useradd script

You can do it as,


--- employee.log ---
# ID Login First Name ast Name
1200 Muthu Muthukumar Kandasamy
....
....


#!/bin/sh
print "Enter group name to add all employee"
read group
groupadd $group

while read line; do

$(echo $line | grep -qEv '^$|^#')
if [[ $? -ne 0 ]]
then
user=$(echo $line | awk '{ print $2 }')
comment=$(echo $line | awk '{ print $3" "$4 }')
uid=$(echo $line | awk '{ print $1 }')
useradd -u $uid -c "$comment" -g $group $user
fi
done

## end ###

Try for two users and delete it. Try again to all.
hth.
Easy to suggest when don't know about the problem!
Abhijeet_3
Frequent Advisor

Re: Useradd script

Thx ,

Suppose I have text file with above information , how to use this text file with your script.
Matthew_50
Valued Contributor

Re: Useradd script

save and upload attach ch_pass binary file to server, and chmod 700 to it,

#cat userlist
60000 loginname1 Tom,Cruise
60001 loginname2 Jerry,Maquire
60002 loginname3 Kevin,Mitnick

#cat script_useradd.sh
#!/bin/ksh
cat userlist|while read $uid $login $comment
do
echo "Adding ... $uid $loginname"
useradd -u $uid -g users -d /home/$loginname -c $comment -m $loginname
./ch_pass $loginname $loginname
done

# chmod 700 script_useradd.sh

simply just execute ./script_useradd.sh

this are sample, change the script to fill your requirement.
Steven E. Protter
Exalted Contributor

Re: Useradd script

while read -r userame
do
# insert the above code here.

done < textfile

This will let you read through the file and process the entire textfile with the code provided above.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Matthew_50
Valued Contributor

Re: Useradd script

forgot to say, that ch_pass used to change user's login password in one line, since every user's password are same as self username, so I think, at this moment, the password security doesn't that matter.