LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices



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

Rep: Reputation: 31
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, 01:25 PM   #2
DoubleOTeC
Member
 
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 helpful...as 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"
fi
else echo >&2 "Cannot create user $user"
fi
done

" -- 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-22-2003, 12:21 AM   #3
hoggin
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
code:
________________________________________

#!/usr/bin/ksh

NEW_USERS="/path/to/text_data_file"
HOME_BASE="/home/"

cat ${NEW_USERS} | \
while read USER PASSWORD GROUP
do
useradd -g ${GROUP} -p ${PASSWORD} -m -d ${HOME_BASE}${USER} ${USER}
done
________________________________________

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)

or

./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.
 
  


Reply


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


All times are GMT -5. The time now is 07:37 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration