LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-07-2004, 03:02 AM   #1
hindll01
LQ Newbie
 
Registered: Sep 2004
Location: New Zealand
Distribution: Fedora Core 1
Posts: 13

Rep: Reputation: 0
Can't add new users from an input file


I need to write a shell script to add a list of newusers in the below format

usernameassword:groupname:fullname

I am really new at Linux (Fedora Core 1), could anybody please give me a hand?

I am having trouble with
1) reading from the input file
2) saving the new users' information into the correct files

Last edited by hindll01; 09-07-2004 at 03:04 AM.
 
Old 09-07-2004, 05:08 AM   #2
gizmo_thunder
Member
 
Registered: Apr 2004
Posts: 101

Rep: Reputation: 15
what do you mean by add new users??
do you want to add users to the system??
or just take some input and write a file??
 
Old 09-07-2004, 05:46 AM   #3
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
Your input file is in this format:

usernameassword:groupname:fullname

and you need to add these users to the system, is that right?

First thing to do in your script would be:
IFS=\015
this sets the 'splitting' character to \n, so you can work with lines that have spaces. Then you could do something like this:
for x in `cat userlist.txt`
do
USER=`echo $x | cut -f 1 -d:`
PW=`echo $x | cut -f 2 -d:`
GRP=`echo $x | cut -f 3 -d:`
NAME=`echo $x | cut -f 4 -d:`
xxxx
done

The lines xxxx are the ones I can't be sure of as I don't use Redhat, but check your man pages for scripts like adduser or useradd, addgroup or groupadd. To set the passwords, you might need to install expect or find a tool that sets passwords from the command line.
 
Old 09-07-2004, 06:12 PM   #4
hindll01
LQ Newbie
 
Registered: Sep 2004
Location: New Zealand
Distribution: Fedora Core 1
Posts: 13

Original Poster
Rep: Reputation: 0
Can't add new users

Yes, I have to add new users to the system from a list of user from an input file that is formatted like this;

username:password:groupname:fullname
username:password:groupname:fullname
username:password:groupname:fullname

and so on...


I have also noticed that when a new user is added to the system their groupname is automatically created using their username.

How can I stop this??
 
Old 09-07-2004, 07:32 PM   #5
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
Check the man page for useradd, you should find the help you need there.

This worked for me:

useradd -g (default group) (other options) username
e.g, to add a user 'fred' using the group 'users' (so it won't create a fred group)
useradd -g users fred
 
  


Reply



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
can't add users to "samba users" in control center g_jakes Linux - Networking 1 05-20-2005 01:28 PM
Shell Script: Add Users from file flobadon Programming 3 12-07-2004 03:49 PM
auto logging out users on input timeout prell Linux - Security 7 09-01-2004 09:27 AM
Help on Administrative Utility (adding users & data from input file) NightWolf_NZ Linux - Software 0 09-10-2003 08:43 PM
a script that go read the users names in a file and automaticly add then with a commo tumemanques211 Programming 2 03-22-2002 02:13 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:08 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