[K12OSN] user account scripts

Huck dhuckaby at paasda.org
Thu Jan 4 22:56:48 UTC 2007


forgot to mention the output file is in the format that webmin likes for 
importing in the user add bulk section...

--Huck

Huck wrote:
> here is a python script I wrote to do it...
> you can modify it to do what you need...
> it takes:
> 
> a text file with
> 
> lastname firstname
> 
> no punctuation...a single space between names...and each person on a new 
> line...
> 
> run 'python ltspname.py' hit 1,2,3,4  in that order
> if you have a 'usernames.txt' file...you can edit around lines 17 and 
> 25..not exactly sure as I don't have it in an editor atm.. where it says 
> /store/usernames.txt and /store/studentlist.txt
> 
> and make those files whichever you want...in menu_choice 1 is the INPUT 
> file...and menu_choice 2 & 3 has the path to the OUTPUT file
> 
> it makes the default password the same as their username for simplicity.
> 
> --Huck
> 
> Ray Garza wrote:
>> Hello Script Gurus,
>>
>> Anyone know how to create user accounts from a text file using scripts?
>>
>> Example:
>>
>> user_accounts.txt
>> "username1","password"
>> "username2","password"
>> "username3","password"
>> "username4","password"
>>
>> convert that list into users on a local machine
>>
>> Better yet I need to convert a dbase file of usernames and passwords 
>> into valid local user accounts. I can convert the dbase file to other 
>> formats if that helps.
>>
>> Thanks
>>
>> Ray
>>
>> _______________________________________________
>> K12OSN mailing list
>> K12OSN at redhat.com
>> https://www.redhat.com/mailman/listinfo/k12osn
>> For more info see <http://www.k12os.org>
>>
>>
> 
> ------------------------------------------------------------------------
> 
> import string
> 
> def print_menu():
>    print '1. Press 1 to (i)mport the namelist.txt file'
>    print '2. Press 2 to (g)enerate usernames'
>    print '3. Press 3 to (p)rint new usernames.txt file'
>    print '4. Press 4 to E(x)it the Program'
> numbers = {}
> menu_choice = 0
> print_menu()
> while menu_choice != 4:
>    menu_choice = input("Type in a number (1-4):")
>    if menu_choice == 1:
>       #Open the file "namelist.txt"
>       in_file = open("/store/studentlist.txt","r")
>       #variable "textfile" gets filled with info from namelist.txt
>       textfile = in_file.readlines()
>       #Close the file "namelist.txt"
>       in_file.close()
>       
>    elif menu_choice == 2:     
>       #The Loopy Loopy
>       namenum = 0
>       out_file = open("/store/usernames.txt","w")
>       print namenum
>       while namenum < len(textfile):
>          #Manipulate the namelist into pieces we can handle
>          mystring = textfile[namenum]
>          newlist = mystring.split()
>          lname = newlist[0]
>          fname = newlist[1]
>          fname = fname[:2]
>          lname = lname[:4]
>          #Concatenate and Write to File
>          out_file.write("create:"+str(lname)+str(fname)+":"+str(lname)+str(fname)+"::505:"+str(newlist)+":/home/"+lname+fname+":/bin/bash:::::"+"\n")
>          print lname+fname+" has been written to file." 
>          namenum = namenum+1
>          print namenum
>       out_file.close()
>       namenum = 0
>    elif menu_choice == 3:
>       #Gimme some output baby!
>       in_file = open("/store/usernames.txt","r")
>       funkytext = in_file.readlines()
>       in_file.close()
>       print funkytext
>    elif menu_choice == 4:
>       pass
>    else:
>       print_menu()
> print "Goodbye!"
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> K12OSN mailing list
> K12OSN at redhat.com
> https://www.redhat.com/mailman/listinfo/k12osn
> For more info see <http://www.k12os.org>




More information about the K12OSN mailing list