Chris Evich wrote:
On 08/29/2012 11:57 AM, John Dennis wrote:
Thanks for the contribution Chris!
Just as an aside if you know Python you can call the IPA commands
directly and use Python to extract and reformat the data, it might be a
lot simpler than doing the bash/awk dance.
I agree that using bash/sed/awk is a bit clunky. I actually did stumble
on the python stuff by accident, but wasn't able to find much reference
/ examples for how to use it. At the time I just needed something quick
to toss-together. Maybe the python docs/examples are different today,
any links handy?
I seem to recall this came up on either freeipa-users or freeipa-devel
but I can't find the thread. Some decent examples got posted.
Here is something I've been twiddling with to add users from a
well-formatted passwd file:
from ipalib import api
from ipalib import errors
name_pattern = re.compile('(\w+) \w (\w+)')
count = 0
fd = open(filename, 'r')
line = fd.readline()
if not line:
line = unicode(line.strip())
(login, passwd, uid, gid, gecos, dir, shell) = line.split(':')
except ValueError, e:
print "mal-formed passwd entry: %s (%s)" % (e, line)
m = name_pattern.match(gecos)
first = m.group(1)
last = m.group(2)
first = u'USER'
last = u'NAME'
gecos=gecos.strip(), homedir=dir, shell=shell,
print "%s already exists" % login
Freeipa-users mailing list