Scripts
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb Site ManagementScripts

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 4th, 2003, 01:17 AM
stunned stunned is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: The Little Red Dot
Posts: 149 stunned User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 23 m 6 sec
Reputation Power: 6
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?

Reply With Quote
  #2  
Old September 5th, 2003, 06:36 AM
druuna druuna is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 137 druuna User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 37 sec
Reputation Power: 0
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.

Reply With Quote
  #3  
Old September 5th, 2003, 10:33 PM
stunned stunned is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: The Little Red Dot
Posts: 149 stunned User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 23 m 6 sec
Reputation Power: 6
Thanks alot. It works!

Reply With Quote
  #4  
Old September 7th, 2003, 08:25 PM
stunned stunned is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: The Little Red Dot
Posts: 149 stunned User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 23 m 6 sec
Reputation Power: 6
ermm by the way how do you compile/execute a ksh in linux terminal?

Reply With Quote
  #5  
Old September 8th, 2003, 06:51 AM
druuna druuna is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 137 druuna User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 37 sec
Reputation Power: 0
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.

Reply With Quote
  #6  
Old October 12th, 2004, 03:59 AM
zameer_india zameer_india is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 1 zameer_india User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #7  
Old October 15th, 2004, 04:20 AM
nima_kh nima_kh is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 2 nima_kh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by druuna
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.

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

Reply With Quote
  #8  
Old April 26th, 2007, 07:06 PM
jamesrossjr jamesrossjr is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 1 jamesrossjr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 36 sec
Reputation Power: 0
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.

Reply With Quote
  #9  
Old March 29th, 2008, 03:44 AM
quarkhirad quarkhirad is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Posts: 3 quarkhirad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 37 m 4 sec
Reputation Power: 0
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

Reply With Quote
  #10  
Old March 31st, 2008, 10:42 AM
bullet's Avatar
bullet bullet is offline
Java Junkie
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jan 2004
Location: Mobile, Alabama
Posts: 3,267 bullet User rank is Captain (20000 - 30000 Reputation Level)bullet User rank is Captain (20000 - 30000 Reputation Level)bullet User rank is Captain (20000 - 30000 Reputation Level)bullet User rank is Captain (20000 - 30000 Reputation Level)bullet User rank is Captain (20000 - 30000 Reputation Level)bullet User rank is Captain (20000 - 30000 Reputation Level)bullet User rank is Captain (20000 - 30000 Reputation Level)bullet User rank is Captain (20000 - 30000 Reputation Level)bullet User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 13 h 26 m 35 sec
Reputation Power: 307
Send a message via ICQ to bullet Send a message via AIM to bullet Send a message via MSN to bullet
Quote:
Originally Posted by quarkhirad
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


Have you ever used expect? That's why I use to generate samba accounts.

Reply With Quote
  #11  
Old April 4th, 2008, 03:22 AM
quarkhirad quarkhirad is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Posts: 3 quarkhirad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 37 m 4 sec
Reputation Power: 0
bullet thanks

But no i never have used expect. Can you please give me some details. Also note i am using ubuntu 7.04.

Reply With Quote
  #12  
Old April 6th, 2008, 12:45 PM
bullet's Avatar
bullet bullet is offline
Java Junkie
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jan 2004
Location: Mobile, Alabama
Posts: 3,267 bullet User rank is Captain (20000 - 30000 Reputation Level)bullet User rank is Captain (20000 - 30000 Reputation Level)bullet User rank is Captain (20000 - 30000 Reputation Level)bullet User rank is Captain (20000 - 30000 Reputation Level)bullet User rank is Captain (20000 - 30000 Reputation Level)bullet User rank is Captain (20000 - 30000 Reputation Level)bullet User rank is Captain (20000 - 30000 Reputation Level)bullet User rank is Captain (20000 - 30000 Reputation Level)bullet User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 13 h 26 m 35 sec
Reputation Power: 307
Send a message via ICQ to bullet Send a message via AIM to bullet Send a message via MSN to bullet
Quote:
Originally Posted by quarkhirad
bullet thanks

But no i never have used expect. Can you please give me some details. Also note i am using ubuntu 7.04.


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

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb Site ManagementScripts > Shell Script to create user in Linux using text file data


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |