LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-01-2011, 06:07 AM   #1
grayceworks
LQ Newbie
 
Registered: Mar 2011
Posts: 3

Rep: Reputation: 0
Can you verify my syntax for creating multiple users in a batch file?


I have been researching this for days now. I've been to some other forums and been put down for asking. Sorry, I am new and haven't read every single man page available yet. *sigh* I had a moderator at another website tell me that I shouldn't expect help for some random script I pulled out of the darkness of the internet.

I asked about the linux command "newusers".

Specifically, I asked if it would do what I need it to do, and if my syntax was right, and if there was anything else I might need to use to accomplish my goal.

I posted all the info about the commands I thought were right, but needed verified. I will post the info here, and hopefully someone will be kind to this newbie and give me some helpful advice rather than unhelpful put-downs.

I had an old win2kpro system with about 300 user accounts. The drive died. So I couldn't export the accounts, they're all lost. I am setting the new system up with suse 11.3, as that's what I use at home on my personal system. However, my dealings with linux have ONLY been on my personal system, so I haven't had the need to create that many accounts on one box before. So I started researching a tool or script or something that would help. I found "newusers".

Also, I noted when creating a single new user thru YAST, it adds the user both to "users" and to "video" groups. So my other question, besides just adding the users in bulk, is whether the commands below will add them to both users AND video? Or will I have to find a way to separately add them to "video"?

What I found so far was that I should do this:

(chmod the batch-user-add.txt file)
# touch /root/batch-user-add.txt
# chmod 0600 /root/batch-user-add.txt

(open the batch-user-add.txt file to edit it)
# vi /root/batch-user-add.txt

(add the following into the batch-user-add.txt file)
Code:
Unit0106:concorderesident:1201:1001:Unit 106:/home/Unit0106:/bin/bash
Unit0107:concorderesident:1202:1001:Unit 107:/home/Unit0107:/bin/bash
Unit0108:concorderesident:1203:1001:Unit 108:/home/Unit0108:/bin/bash
Unit0109:concorderesident:1204:1001:Unit 109:/home/Unit0109:/bin/bash
Unit0201:concorderesident:1205:1001:Unit 201:/home/Unit0201:/bin/bash
Unit0202:concorderesident:1206:1001:Unit 202:/home/Unit0202:/bin/bash
Unit0203:concorderesident:1207:1001:Unit 203:/home/Unit0203:/bin/bash
Unit0204:concorderesident:1208:1001:Unit 204:/home/Unit0204:/bin/bash
Unit0205:concorderesident:1209:1001:Unit 205:/home/Unit0205:/bin/bash
Unit0206:concorderesident:1210:1001:Unit 206:/home/Unit0206:/bin/bash
Unit0207:concorderesident:1211:1001:Unit 207:/home/Unit0207:/bin/bash
Unit0208:concorderesident:1212:1001:Unit 208:/home/Unit0208:/bin/bash
Unit0209:concorderesident:1213:1001:Unit 209:/home/Unit0209:/bin/bash
Unit0210:concorderesident:1214:1001:Unit 210:/home/Unit0210:/bin/bash
Unit0301:concorderesident:1215:1001:Unit 301:/home/Unit0301:/bin/bash
Unit0302:concorderesident:1216:1001:Unit 302:/home/Unit0302:/bin/bash
Unit0303:concorderesident:1217:1001:Unit 303:/home/Unit0303:/bin/bash
Unit0304:concorderesident:1218:1001:Unit 304:/home/Unit0304:/bin/bash
Unit0305:concorderesident:1219:1001:Unit 305:/home/Unit0305:/bin/bash
Unit0306:concorderesident:1220:1001:Unit 306:/home/Unit0306:/bin/bash
(save the file, and then run the linux command newusers)
# newusers /root/batch-user-add.txt

I didn't find it somewhere in the dark on the internet. newusers is a linux command. I found the info about how to use it between the man pages and various bulletin board posts which have bits and pieces of it, but so many of them have variations on the above commands, so I'm not sure if I've got it right or not. So I am trying to follow the directions between that and the linked man pages of passwd and other related commands, and am trying to find out if it will
A) do what I need it to do,
and B) if I've got the syntax right.

http://linux.die.net/man/8/newusers
http://linux.die.net/man/5/passwd


I don't know how many other ways I can word my questions? I know I'm new to all this, but I HAVE been doing my homework and reading for days now, both man pages and bulletin boards, and articles, and the specific documentation that came with my installation, and trying to ask intelligent questions.

I'm getting discouraged with this and about ready to go back to windoze just to get this computer up and running before the 300 residents of this building throw a fit. I'm very frustrated, and kinda sad about the level of unfriendliness and unhelpfulness I've encountered among the linux "experts". This is pretty much my last try at hoping someone might actually help?
 
Old 03-01-2011, 02:51 PM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Distribution: Debian
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
While I appreciate your frustration, adding several paragraphs detailing the many unhelpful people you've met doesn't help us help you and can come across perhaps differently to the way you intended it to.

I believe your format is correct for your input file. And what it should do is create a user from each of the lines, according to the information you've given it and the information you get when you type 'man newusers'. I don't think that they will be added to the 'video' group:

Quote:
This field is used to define the primary group ID for the user.
If this field contains the name of an existing group (or a group
created before by newusers), the GID of this group will be used as
the primary group ID for the user.

If this field is a number, this number will be used as the primary
group ID of the user. If no groups exist with this GID, a new group
will be created with this GID, and the name of the user.

If this field is empty, a new group will be created with the name
of the user and a GID will be automatically defined by newusers to
be used as the primary group ID for the user and as the GID for the
new group.
From the manpage

So if you already have a group #1001, then they will be added to that; if not, it will be named 'Unit0106' and they will all be added to it. In order to add them to the 'video' group, I've written you a nice little script:

Code:
for i in $(cat userfile.txt | grep "^[^:]*" -o)
do
useradd -G video $i
done
Just type that into the prompt, with 'userfile.txt' being the file you posted above. Also, if you want to add it to another group as well (ie. 'sound' or 'games', just change 'video' in the command above to 'video,sound,games')

Hope this helps,
 
1 members found this post helpful.
Old 03-02-2011, 01:35 AM   #3
grayceworks
LQ Newbie
 
Registered: Mar 2011
Posts: 3

Original Poster
Rep: Reputation: 0
I know. I apologize. I was incredibly frustrated.

Thank you for your advice on this. Do I type each line of that on its own line (hitting return after each?) or do I enter it all on one line?


Also, a question on my input file. It says gid or group id, so is that referring to the group name (ie "users") or the group number (ie "1001") I just want to be very sure before I run this file and create 300+ accounts.


Thank you again!



Quote:
Originally Posted by Snark1994 View Post
While I appreciate your frustration, adding several paragraphs detailing the many unhelpful people you've met doesn't help us help you and can come across perhaps differently to the way you intended it to.

I believe your format is correct for your input file. And what it should do is create a user from each of the lines, according to the information you've given it and the information you get when you type 'man newusers'. I don't think that they will be added to the 'video' group:



From the manpage

So if you already have a group #1001, then they will be added to that; if not, it will be named 'Unit0106' and they will all be added to it. In order to add them to the 'video' group, I've written you a nice little script:

Code:
for i in $(cat userfile.txt | grep "^[^:]*" -o)
do
useradd -G video $i
done
Just type that into the prompt, with 'userfile.txt' being the file you posted above. Also, if you want to add it to another group as well (ie. 'sound' or 'games', just change 'video' in the command above to 'video,sound,games')

Hope this helps,
 
Old 03-02-2011, 05:21 AM   #4
grayceworks
LQ Newbie
 
Registered: Mar 2011
Posts: 3

Original Poster
Rep: Reputation: 0
where is newusers?

Which versions of linux contain newusers by default? And is there a way to add it if it's not included by default?

Last edited by grayceworks; 03-02-2011 at 06:31 AM.
 
Old 03-02-2011, 06:57 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,369

Rep: Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753
Tell us which distro you are using; in fact, add it to your profile so we don't need to ask again next time.

Login as root and run
Code:
which newusers
That should tell you where it is if you have it.
If you have an rpm based distro eg RHEL, Centos, Fedora etc, you can also try
Code:
rpm -qa |grep -i newusers
Also check in your pkg mgr.
 
1 members found this post helpful.
Old 03-03-2011, 02:04 AM   #6
Snark1994
Senior Member
 
Registered: Sep 2010
Distribution: Debian
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
Quote:
Originally Posted by grayceworks View Post
Thank you for your advice on this. Do I type each line of that on its own line (hitting return after each?) or do I enter it all on one line?
Yeah, it should come up with a different prompt to show you're still entering the same command

Quote:
Also, a question on my input file. It says gid or group id, so is that referring to the group name (ie "users") or the group number (ie "1001") I just want to be very sure before I run this file and create 300+ accounts.
Group number. If it already exists, then they're added to that one; if it doesn't, it's created with the name of the first user which is added to it

EDIT: Rereading the man-page you can actually use the group name as well... So either should work
 
1 members found this post helpful.
  


Reply

Tags
shell



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating multiple users hrishikesh_am Linux - General 3 06-21-2008 12:14 PM
creating multiple users naumz Linux - Newbie 5 10-05-2007 05:36 PM
creating multiple users sikkalgopal Linux - Newbie 3 07-06-2007 06:01 AM
Creating multiple users in Kmail with a single KDE user jonole Linux - Software 3 10-03-2004 12:36 AM
script for creating multiple users d3funct Programming 1 08-21-2001 05:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration