Re: Linux : create a user if not exists

2011-08-16 Thread Smaine Kahlouch
Le 16/08/2011 17:56, Alexander Kapps a écrit : On 16.08.2011 16:57, smain kahlouch wrote: 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 ... retur

Re: Linux : create a user if not exists

2011-08-16 Thread Alexander Kapps
On 16.08.2011 16:57, smain kahlouch wrote: 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 ... >>> finduser('realuser') realuser

Re: Linux : create a user if not exists

2011-08-16 Thread Terry Reedy
On 8/16/2011 10:57 AM, smain kahlouch wrote: 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 ... >>> finduser('realuser') realuse

Re: Linux : create a user if not exists

2011-08-16 Thread smain kahlouch
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 ... >>> finduser('realuser') realuser user exists True >>> finduser('blabla') Traceba

Re: Linux : create a user if not exists

2011-08-16 Thread Christian Heimes
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 li

Re: Linux : create a user if not exists

2011-08-16 Thread Chris Rebert
On Tue, Aug 16, 2011 at 12:45 AM, smain kahlouch wrote: > Hi all, > > I'm learning the python language and i'm trying to create a user if it is > not found in the system. > I figured it out by doing the following thing : > def finduser(user): > ... for line in open('/etc/passwd'): > ...  

Linux : create a user if not exists

2011-08-16 Thread smain kahlouch
Hi all, I'm learning the python language and i'm trying to create a user if it is not found in the system. I figured it out by doing the following thing : >>> def finduser(user): ... for line in open('/etc/passwd'): ... if line.startswith(user): ... print user,