[Techtalk] help with python script for batch useradd
Aaron Malone
aaron at munge.net
Tue Jan 6 14:51:14 EST 2004
On Tuesday 06 January 2004 13:21, Carla Schroder wrote:
> This was written by Aaron Malone, who used to hang out here.
And decided to rejoin the list and see what was going on these days. :)
Actually, the script I gave you should work fine for that unaltered.
It actually uses ':' as the separator character between username and
realname, so if you have, say:
carlas:Carla Schroder,,,,foo
as input, it should add you as:
useradd -m -c "Carla Schroder,,,,foo" carlas
The bug you may hit there is if someone has a colon in their GECOS/
realname field. This can be fixed by changing line 24 to:
username, realname = line.split(':', 1)
The extra argument to string.split is the 'maxsplit' -- that is, it'll
only split that line once, so you don't have to worry about further
colons in the input.
--
Aaron Malone
aaron at munge.net
More information about the Techtalk
mailing list