LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   add user script? (https://www.linuxquestions.org/questions/linux-software-2/add-user-script-97872/)

ezra143 09-28-2003 12:05 PM

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

DoubleOTeC 09-28-2003 12:25 PM

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"

hoggin 10-21-2003 11:21 PM

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.


All times are GMT -5. The time now is 05:42 PM.