If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > script for adding a new user

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-31-04, 21:40
iamagirl iamagirl is offline
Registered User
 
Join Date: Mar 2004
Posts: 10
script for adding a new user

Hi all;

I'm receiving great answers from this board.Thanks alot for anyone who replys to my questions.I'm new in unix shell scripting and also having alot of questions

I have a new one.

I'm trying to create a little script for the root menu that should be able to add a new user.The system has 4 different groups such as marketing,sales. ..I also have a db file that has

EmployeeNumber, FirstName, LastName, Location, Department
************************************************** *******
12345, Tiger, Woods, Key West, Marketing
12341, Flip, Wilson, Los Angeles, Entertainment
-----------
My little script should be able to:
*Prompt for the name of the data file
*shoul create user accounts for each user
*Users will belong to one of: mktg, ent, trade, or mgmt groups, based on the Department field
*Their usernames will be first_last based on the FirstName and LastName fields.
*They will all be created with Bash Shell defaults, under /home with the default /etc/skel template files included in their new home directories.
*Display the records for the new users ONLY from /etc/passwd
*Return to the menu

Can anyone let me know where I am suppose to start from?
Belinda
Reply With Quote
  #2 (permalink)  
Old 04-01-04, 07:27
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
Code:
Loop 
  Prompt for the name of the data file
Until data file exists

For every record of data file
Do
   Determine user name
   Determine user group
   Determine user home directory
   Verify that user doesnt already exist, if exist proceed next record
   Create home directory if not exists
   Create the user, if error proceed next record
   Copy template files from /etc/skel to the home directory
   Search and display user definition from /etc/password
End For
You'll need to use (it's just suggestions, it may have several solutions ):

Loop ... Until : 'while' or 'until'
Prompt : 'read'
For every .. End For : 'while' 'IFS' 'read' 'continue'
Verify user : grep /etc/password
Verify file or dir : 'test -e' 'test -d'
Create home dir : 'mkdir'
Create user : 'adduser' or other system specific command
Copy template : 'cp'
Search and display : 'grep'
__________________
Jean-Pierre.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On