Adding new users via Shell script
Hey,
I need to create a shell script which adds about 10-20 users automatically with username of the form "scoecomp1","scoecomp2" so on and default password "abc". How do i go about doing this as when the "adduser" command is executed in shell script the shell waits for inputs like username,uid etc from user. How do i make the script fill in these inputs? |
u could use useradd instead
useradd <username> -d <homedir> -g <group> -s <dflt shell> -c <users name> -p <password> and u could try this script but i havent tried it but atleast u could look at its code http://www.linuxquestions.org/questi...useradd+script |
Heres a little python script that should do the trick:
Code:
SEE CHANGES BELOW <EDIT>Also make sure all the 'useradd' switches are to your likeing. This script will create a home directory for each user. Not sure if thats what you want but you can easily edit things.</EDIT> |
Also note that the password that the -p option expects
is already ENCRYPTED ... if you use -p abc the user won't be able to log in at all ... Code:
quoted from man useradd Cheers, Tink |
Good eye Tinkster. This should work now(if you have crypt installed) but I haven't tested it.
Code:
#!/usr/bin/env python |
Hey all,
Thanx for the replies. But it would be great if i could get this done without using Python. |
Bash Script.
Give this a try. Tested on bash.
Code:
: |
Quote:
|
Give this one a try:
Code:
USER_ACCT="scoecomp" |
Thanx all.
|
Creating users using script
for i in $(seq 1 20);do useradd scoecomp$i;echo "abc" | passwd scoecomp$i --stdin;done
Just copy n paste the above script in ur terminal and ur done !! |
All times are GMT -5. The time now is 10:36 PM. |