[K12OSN] Username conversion script
Huck
dhuckaby at paasda.org
Wed Aug 18 22:11:28 UTC 2004
#start of script
import string
#wanted menu to be able to use '1 letter hotkeys' but I'm not THAT
advanced yet! a !=4 || !=x might work..but haven't had time to fiddle
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 "usernames.txt" a textfile with your user's
FIRSTNAME LASTNAME on newlines
in_file = open("c:\\usernames.txt","r")
#variable "textfile" gets filled with info from usernames.txt
textfile = in_file.readlines()
#Close the file "usernames.txt"
in_file.close()
elif menu_choice == 2:
#The Loopy Loopy
namenum = 0
out_file = open("c:\\usernameswebmin.txt","w")
print namenum
while namenum < len(textfile):
#Manipulate the namelist into pieces we can handle
mystring = textfile[namenum]
newlist = mystring.split()
fname = newlist[0]
lname = newlist[1]
fname = fname[:2]
lname = lname[:4]
#Concatenate and Write to File
#create:USERNAME:PASSWD::::/home/username:/bin/bash:::::
format for webmin module
out_file.write("create:"+lname+fname+":"+lname+fname+"::::/home/"+lname+fname+":/bin/bash:::::\n")
print lname+fname+" has been written to file."
#Great lets increment and show where we are in the array
namenum = namenum+1
print namenum
#We're all done so lets close the file!
out_file.close()
namenum = 0
elif menu_choice == 3:
#Gimme some output baby! Lets see what we've added
in_file = open("c:\\usernameswebmin.txt","r")
funkytext = in_file.readlines()
in_file.close()
print funkytext
elif menu_choice == 4:
pass
else:
print_menu()
print "Goodbye!"
#end of script
Jim Kronebusch wrote:
>>If any would like this python script let me know!
>>hand typing 200+ usernames became too much for me last year!
>>Automation
>>is lovely!
>>
>>
>
>I would love a copy of it or a link to where to get it. Sounds cool,
>I'd like to take a look at it.
>
>---
>Outgoing mail is certified Virus Free.
>Checked by AVG anti-virus system (http://www.grisoft.com).
>Version: 6.0.736 / Virus Database: 490 - Release Date: 8/9/2004
>
>
>
>_______________________________________________
>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