|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Shell Script to create user in Linux using text file data
Shell Script to create user in Linux using text file data.
Is it possible? |
|
#2
|
|||
|
|||
|
Yep it is.
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. Last edited by druuna : September 5th, 2003 at 11:07 AM. |
|
#3
|
|||
|
|||
|
Thanks alot. It works!
|
|
#4
|
|||
|
|||
|
ermm by the way how do you compile/execute a ksh in linux terminal?
|
|
#5
|
|||
|
|||
|
The same way you execute sh/bash:
scriptname.ksh <enter> (if found in PATH) or ./scriptname.ksh <enter> 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. Last edited by druuna : September 8th, 2003 at 06:55 AM. |
|
#6
|
|||
|
|||
|
Iam not able to login after creating a user using script
Hi, Everybody... Good Afternoon
Why I am not able to login to create a user .... by using the following script.. #!/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 using this script i create users but i am not able to login why it was... I am really appreciate if some body helps me resolving this issue.... Zameer Ahmed Syed |
|
#7
|
|||
|
|||
|
Quote:
hey, I am supposed to do a big project on unix shell script, but i dont really know wot to do, any1 can help me and give me some ideas about some projects involving shell script? e.g. internet analyzer using shell? pliz contact me on nima_h_S@yahoo.com regards Nima |
|
#8
|
|||
|
|||
|
I am using the above code to add users to a red hat Linux box; it works, but I want to add a name to the account useradd -c 'Test Test' but I am unable cause the space as the delimiter in the file that the script reads thinks a first and last name are two variables. Also, the password reset part the script does not work. The script will run but the password I set in the file does not work allow the user to log in. Any help would be great.
|
|
#9
|
|||
|
|||
|
adding samba
thanks druuna
The script worked. Now what i need is to allow all these users to be able to access samba. To this i need to execute the following for every single user that i created by using ur shell script Code:
sudo smbpasswd -a username New smb password : ------- retype new smb password: ----- Can you design a shell script for me to do this?? Thanks |
|
#10
|
||||
|
||||
|
Quote:
Have you ever used expect? That's why I use to generate samba accounts. |
|
#11
|
|||
|
|||
|
bullet thanks
But no i never have used expect. Can you please give me some details. Also note i am using ubuntu 7.04. |
|
#12
|
||||
|
||||
|
Quote:
This is a simple expect script for doing this. Code:
#!/usr/bin/expect
spawn /usr/local/samba/bin/smbpasswd -a [lindex $argv 0]
expect "New*:" {send "[lindex $argv 1]\r"}
expect "Retype*:" {send "[lindex $argv 1]\r"}
expect "Password*" {break}
exit 0
Here, of course, I assume expect is in /usr/bin, and smbpasswd is in /usr/local/samba/bin Assuming the script is named smbpasswd.exp, it would be called like this. /path-to/smbpasswd.exp username password |
![]() |
| Viewing: Dev Shed Forums > Web Site Management > Scripts > Shell Script to create user in Linux using text file data |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|