[Tutor] adding users from a script
Cerulean Rodent
cerulean_rodent@yahoo.co.uk
Fri, 14 Sep 2001 16:00:43 +0400 (MSD)
So here we go. Thanks to everyone for the tips - I'm posting the
functional version of the script I was working at. It might look pretty
ugly at times - but it's the first thing halfway resembling a programme
that I've written, so maybe all hope is not lost...
#!/usr/bin/python
import os
import re
import whrandom
rnd = whrandom.whrandom()
validfirst = "abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ23456789"
# l, 0, 1 & o omitted so as not to confuse the (l)users
pwlen = 8
pw = ""
idx = 0
while idx < pwlen:
pw = pw + rnd.choice(validfirst)
idx = idx + 1
encr = os.popen('mkpasswd ' + pw + ' dread', 'r')
z = re.sub(r'\n','',encr.read())
nomme = raw_input("\nPrint your desired username:\n>>")
if nomme != '':
os.system('useradd -p ' + z + ' -s /bin/false' + ' ' + '-G mail' + ' ' + nomme)
else:
print "\nYou must enter a valid username!"
logfile = open('passlog', 'a')
logfile.write(nomme + "\t" + pw + "\n")
logfile.close
Scary, huh? The gurus must be grinding their teeth in horror wishing to
orally decapitate yours truly... newbies are a plague, and something must
be done to us - since murder is illegal, one has to think of something
else...
PM XXIII
-----------------------------------------------------
" The stars go waltzing out in blue and red,
And arbitrary blackness gallops in:
I shut my eyes and all the world drops dead. "
--Sylvia Plath
-----------------------------------------------------