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 Thanks David
David Leon 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 createWhat's the question? How to do it? Parse the text file and use something like useradd to add the accounts, is probably the quickest way. nate
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 taskYour 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
Greetings, On 8/3/09, 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 > > Thanks > DavidI have used newusers command in conjunction with a text file in passwd file type fields. man newusers should be your friend here and if they are to be replicated across nodes as in a cluster, wrap it up in a scrip with scp for /etc/passwd, /etc/group, /etc/shadow and /etc/gshadow HTH Thanks and regards Rajagopal