[CentOS] help - batch account creation

Mon Aug 3 18:47:31 UTC 2009
Eduardo Grosclaude <eduardo.grosclaude at gmail.com>

On Mon, Aug 3, 2009 at 3:04 PM, David Leon<dleon741210 at gmail.com> wrote:
> Hello guys
>
> I have a new Centos 5.3 running, and I have a text file with a bunch
> of accounts (more than 100) that I should create
> .
> File format is like this
>
> user1 pasword1
> user2 passwrd2
> ....
>
> How can I do this task easier than creating user one by one by hand?
> Need some help for building an script to achieve this task

Your script may loop over your file using useradd to create users like this:

while true
do
        read username passwd
        if [ "$username" == "" ]
        then
                exit
        fi
        useradd $username
done

Feed the file into the script as std input, like "./script < file".

As for setting their passwords, the chpasswd command may be what you need.

Chpasswd likes ":" between username and password, while you have
spaces in your file. So edit the file and remember to set IFS=: at the
beginning of your script.

I usually don't trust enough my own scripting skills. So I'm reluctant
to make a script that may radically change the state of my system's
user base. You may feel more comfortable making a script which simply
builds up and outputs the proper commands, gather this output into a
file, give it a good look and only then execute these commands.

-- 
Eduardo Grosclaude
Universidad Nacional del Comahue
Neuquen, Argentina