Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

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 October 13th, 2012, 03:34 AM
gini_2012 gini_2012 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 2 gini_2012 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 28 m 38 sec
Reputation Power: 0
Adding multiple users

Hello,

I am new to Python, and I have to create a script (using Python) to add multiple users ( > 100 ) into Linux servers.

Obviously, what I am trying to do here is automate the task of adding users into servers.

Can I have some tips/advice on how to start and what to do? Giving an example of code would be a great help for me?

P/S : Is Python difficult to learn? How fast will I be able to catch up?

Thanks,


Reply With Quote
  #2  
Old October 13th, 2012, 11:26 AM
Purity_Lake Purity_Lake is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 33 Purity_Lake User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 25 m 17 sec
Reputation Power: 2
Quote:
Originally Posted by gini_2012
Hello,

I am new to Python, and I have to create a script (using Python) to add multiple users ( > 100 ) into Linux servers.

Obviously, what I am trying to do here is automate the task of adding users into servers.

Can I have some tips/advice on how to start and what to do? Giving an example of code would be a great help for me?

P/S : Is Python difficult to learn? How fast will I be able to catch up?

Thanks,


in all honesty for what you are hoping to do is beyond beginner python, sure python is "easier" that some languages but it doesn't mean it isn't hard

all programming languages are hard regardless when u r a beginner, it will take a while to perfect the basics

Reply With Quote
  #3  
Old October 13th, 2012, 12:00 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,458 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 4 Days 6 h 26 m 43 sec
Reputation Power: 403
I'd probably write a bash script for the task, since basically you'd need to invoke unix commands.
Do you know how to add an account to a unix system using the unix command line?
Do you know what groups and privileges each of these should belong to or have?
What does your input file look like?
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
  #4  
Old October 13th, 2012, 08:30 PM
gini_2012 gini_2012 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 2 gini_2012 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 28 m 38 sec
Reputation Power: 0
I definitely know how to add a user account into the unix system, the simplest one being :

#useradd -m [username],

and more complex one, being the ability to add user groups, etc to the user, e.g :

#useradd -g guests -G www,accounting -d /home/guestuser -s /usr/bin/bash3 -m guestuser

g here is the primary group where the user will belong to, &
G is the secondary group
d is the home directory the user will belong to
s is the shell path

I managed to get some lines for user adding using python :
-------------------------------------------------------------------
import os
import crypt

>>>username = raw_input ("Please enter username : ")
>>>password = raw_input ("Please enter password : ")

os.system ("useradd -p "'+crypt.crypt (password, "22")+" "+username)
-------------------------------------------------------------------

Is this correct? Is there anything else that I have to add/modify in the script??


Reply With Quote
  #5  
Old October 13th, 2012, 09:05 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,458 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 4 Days 6 h 26 m 43 sec
Reputation Power: 403
Code:
import os
import crypt

while True:
    username = raw_input ("Please enter username : ")
    password = raw_input ("Please enter password : ")
    os.system ("useradd -p "'+crypt.crypt (password, "22")+" "+username)
exit with ^C

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Adding multiple users

Developer Shed Advertisers and Affiliates



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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap