Linux / UNIX Tech Support Forum
This is a discussion on How to create multiple user account? within the Shell scripting forums, part of the Development/Scripting category; I found the link to create multiple user account by typing out all the account. But how to create using ...
|
Register free or login to your existing account and remove all advertisements. |
|
|||||||
| Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
I found the link to create multiple user account by typing out all the account. But how to create using linux shell scripting if i want to create 50 account which are almost the same but only difference is the user number and some other number is different which is in running order?
Eg. First user will have the following details: Login name: user00 Password: pwd00 UID: 1000 GID: 123 Informational name: “Student Index 00” Home directory: /home/SI00 Login shell: /bin/sh the last user will have the following details: Login name: user49 Password: pwd49 UID: 1049 GID: 123 Informational name: “Student Index 49” Home directory: /home/SI49 Login shell: /bin/sh Last edited by droidwork; 06-08-2007 at 08:25 PM. |
| Sponsored Links | ||
|
|
|
||||
|
You need to use newusers command and a text file with this info.
data.txt file Code:
user00:pwd00:1000:123:Student Index 00:/home/SI00:/bin/sh user01:pwd00:1001:123:Student Index 01:/home/SI01:/bin/sh ..... ... .. user49:pwd49:1049:123:Student Index 49:/home/SI49:/bin/sh Code:
for u in $(seq 00 05); do echo "user${u}:pwd${u}:$(expr 1000 + $u):123:Student Index ${u}:/home/SI${u}:/bin/sh"; done > data.txt
Code:
newusers data.txt PS: If you are doing this first time, make a backup of all all password related files aka /etc/passwd, /etc/group, /etc/shadow and others
__________________
Vivek Gite Linux Evangelist |
|
||||
|
change seq parameters from 00 05 to 00 49
__________________
Vivek Gite Linux Evangelist |
|
|||
|
sorry, i dont really get the code.. how come when create 50 user is 00 05 and 80 user is 00 49? Can explain the code part by part?
Last edited by droidwork; 06-10-2007 at 03:15 PM. |
|
|||
|
somehow i cant get it to work.. it create only 1 funny account and not.. mayb can someone teach me step by step?
i write the code in vi data.txt.. then after :wq!, use newusers data.txt.. is this the right way? Last edited by droidwork; 06-12-2007 at 05:31 PM. |
|
||||
|
Noop..
Login as root user goto /tmp Code:
cd /tmp Code:
for u in $(seq 00 49); do echo "user${u}:pwd${u}:$(expr 1000 + $u):123:Student Index ${u}:/home/SI${u}:/bin/sh"; done > data.txt
Now just add new users Code:
newuser data.txt
__________________
Raj Linux rulz. I have never turned back in my life ; I shall not do so today.. haha |
|
|||
|
thank you very much.. anyway can tell me what does $(expr 1000 + $u): do? i know u is for the value.. and 1000 is the starting.. but what does expr for?
Last edited by droidwork; 06-12-2007 at 06:41 PM. |
|
||||
|
Quote:
ARG1 + ARG2 arithmetic sum of ARG1 and ARG2 If $u=2, expr 1000 + ${u} = 1002 Read man page of expr for upto-date information.
__________________
Vivek Gite Linux Evangelist |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Create new user account in Ubuntu Linux from command line | sweta | Getting started tutorials | 3 | 02-07-2010 01:15 PM |
| Unable to create user | vaibhav.kanchan | Getting started tutorials | 3 | 12-07-2007 11:46 AM |
| how to create super user | click007 | Getting started tutorials | 12 | 08-28-2007 09:14 PM |
| HP UX creating user account with SAM - it is easy to use | rockdalinux | HP-UX | 0 | 12-20-2006 03:01 PM |
| how to create multiple file in a single command | selvam | Shell scripting | 3 | 07-26-2006 02:01 AM |