LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-18-2004, 08:08 AM   #1
polis
LQ Newbie
 
Registered: May 2004
Posts: 4

Rep: Reputation: 0
Unhappy create users using script


hi... I need to create many user on my redhat 9, so its unpractical to ceate one by one, so how can I create many user using script that can read from a source file, should I use perl script??? or bash script?? have someone written it...please help me...
 
Old 05-18-2004, 08:19 AM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Try this....

The file /home/names.txt has the user names (lower case) , groups and the Linux/Samba password.
The Linux and Samba passwords are the same and the user should change them soon after login.
The groups can already exist.

For example.....

fred service 12qwaszx
sam hr 34erdfcv
joe maint 56tyghbn
sally sales 78uijkm

Code:
#!/bin/bash
#
# Ensure that root is running the script.
##
WHOAMI=`/usr/bin/whoami`
if [ $WHOAMI != "root" ]; then
echo "You must be root to add news users!"
exit 1
fi
#
clear
NEW_USERS="/home/names.txt"

cat ${NEW_USERS} | \
while read USER GROUP SMBPASS ; do
   
   groupadd ${GROUP} 2> /dev/null
   adduser ${USER} -g ${GROUP}

   (echo $SMBPASS; echo $SMBPASS) | passwd --stdin ${USER} > /dev/null
   echo Added user ${USER}

   smbpasswd -e ${USER} -w ${SMBPASS} > /dev/null
   (echo $SMBPASS; echo $SMBPASS) | smbpasswd -as ${USER}
   echo -e "${USER} = ${USER}" >> /etc/samba/smbusers
done

Last edited by homey; 04-05-2005 at 02:33 PM.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
create new users in squirellmail bharath144 Linux - Software 1 11-26-2005 03:02 PM
perl script help required to create users and changing the owner to pericular folder sridhar11 Programming 2 10-25-2005 02:16 PM
Can't create users! Zeke55 Linux - Newbie 9 12-08-2004 01:23 PM
Create users in Samba br_sriram Linux - Software 2 09-24-2004 11:49 AM
I cant create functional users! bcf2 Mandriva 4 08-31-2004 08:58 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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