#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    2
    Rep 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,

  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2012
    Posts
    33
    Rep Power
    3
    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
  4. #3
  5. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,962
    Rep Power
    481
    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 and Makefiles!
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    2
    Rep 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??

  8. #5
  9. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,962
    Rep Power
    481
    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
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo