[Tutor] adding users from a script
alan.gauld@bt.com
alan.gauld@bt.com
Wed, 12 Sep 2001 17:43:53 +0100
> I haven't got the foggiest as to whether introductory messages are
> obligatory
Nope, just ask quetions :-)
> import whrandom
> rnd = whrandom.whrandom()
>
> validfirst =
> "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ23456789"
You might find it easier in future to use:
validfirst = string.letters + string.digits[2:]
I notice you disallow 1 and 0 - any reason?
> pwlen = 8
> pw = ""
> idx = 0
>
> while idx < pwlen:
> str = validfirst[rnd.randint(0,(len(validfirst)-1))]
str = rnd.choice(validfirst) # a bit easier?
> pw = pw + str
Could combine these two lines:
pw = pw + rnd.choice(validfirst)
> idx = idx + 1
>
> print "\nEnter your desired username:\n"
> nomme = raw_input (">>")
Why not combine these:
nomme = raw_input("\nEnter your desired username:\n>> ")
> os.system ('useradd ' + nomme)
>
> Now this is the part I got really stuck on
> os.system ('passwd ' + nomme) gets me a prompt
Thats why you need to use popen or popen2.
They allow you to write to that prompt.
> correct syntax are far from clear.
Treat it as a file. In your case open to write
- you want to send data to it...
Try searching the ActiveState version of this list
archive for popen you should find lots of code examples.
That should solve it.
Alan G