Linux : create a user if not exists
smainklh at gmail.com
Tue Aug 16 16:57:27 CEST 2011
Ok than you. You're right but it doesn't help me :
I replaced it :
>>> def finduser(user):
... if pwd.getpwnam(user):
... print user, "user exists"
... return True
... return False
realuser user exists
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 2, in finduser
KeyError: 'getpwnam(): name not found: blabla'
As you can see, i just want to look for a user and if it doesn't exist, an
action is taken (create user).
Maybe you have another way to do that check ?
2011/8/16 Christian Heimes <lists at cheimes.de>
> Am 16.08.2011 10:04, schrieb Chris Rebert:
> > You can replace the /etc/passwd parsing with a call to pwd.getpwnam():
> > http://docs.python.org/library/pwd.html#pwd.getpwnam
> You should replace it. /etc/passwd is not the only source for users.
> /etc/nsswitch.conf may list more user and group sources like nis/yp,
> LDAP and so on.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list