Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 09-28-2003, 12:05 PM   #1
Registered: Aug 2003
Location: NY
Distribution: RH9, RH8, Slack, Vector
Posts: 497

Rep: Reputation: 32
add user script?

Anyone familiar with a script to add multiple users to the machine and smb froma text file? I have about 100 users to add monday and would like an easy way to do this. TIA
Old 09-28-2003, 12:25 PM   #2
Registered: Aug 2003
Location: Dominica
Distribution: RedHat, FC1, FC3, FC4
Posts: 266

Rep: Reputation: 30
useradd -p

i had a similar issue and found this i'm not sure if the link is correct this is what i just happened to have copied from the guys response ...

"OK. Create your text file so that each line contains one username and its password, separated by one or more space or tab characters. For example, a line from this file might read:
harvey orange
The script to read it is below. This is actually a simpler than the other one, because it doesn't have to construct the usernames.

#! /bin/bash
# Creates a set of new users and assigns them passwords.
# User names and passwords are read from the standard input.
while read user password junk
do if useradd -m -g 501 "$user"
then if echo "$password" | passwd --stdin "$user"
then : # User successfully created.
else echo >&2 "Cannot set password for user $user"
else echo >&2 "Cannot create user $user"

" -- linuxquestions guy...(whose name, unfortunately, escapes me)

now name the script what ever u wish and execute it as follows:

#$: ./[name of script] <[list of users and passwords]

let me know it this helps....and do a search for "useradd -p"
Old 10-21-2003, 11:21 PM   #3
LQ Newbie
Registered: Oct 2003
Posts: 1

Rep: Reputation: 0
User Script

Here's a quick and dirty example.

You did not tell which info is in the text file and it's layout, so i'm goin to assume the following:

- 1 line per newuser,
- username password group are the space seperated fields



cat ${NEW_USERS} | \
useradd -g ${GROUP} -p ${PASSWORD} -m -d ${HOME_BASE}${USER} ${USER}

From here you should be able to expand/add/subtract things you want/don't want.

The same way you execute sh/bash:

scriptname.ksh <enter> (if found in PATH)


./scriptname.ksh <enter>

If you don't have ksh, it could be that ksh (pdksh) is not installed by default (Suse doesn't, don't know about RedHat).

It should reside in /usr/bin or /bin. /bin/ksh should be linked to /usr/bin/ksh ( /bin/ksh -> ../usr/bin/ksh ).

But you don't need to worry if ksh isn't installed, bash is (almost) as good. Just change #!/usr/bin/ksh to #!/bin/sh or #!/bin/bash (sh should be linked to bash: /bin/sh -> bash.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
add user script satinet Linux - General 2 10-21-2005 02:48 AM
add user bash script noir911 Programming 4 08-13-2005 08:24 AM
What add user script you use for Samba 3.0.3-5? subaruwrx Linux - Networking 3 07-19-2004 11:19 AM
CGI Script add user to redhat 9 djkoe Linux - General 1 02-08-2004 04:20 PM
Add User Shell Script DAC Programming 2 10-13-2002 03:12 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:48 AM.

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