User Identification

B

Bob Parnes

I have a python program on a server of an all-linux network. It needs to
record the user name running it. Is there a way for the program to extract
the name from the system without a separate log-in dialog?

Bob Parnes
 
F

Fredrik Lundh

Bob said:
I have a python program on a server of an all-linux network. It needs to
record the user name running it. Is there a way for the program to extract
the name from the system without a separate log-in dialog?

how about:
'gromit'

</F>
 
L

Laszlo Zsolt Nagy

Bob said:
I have a python program on a server of an all-linux network. It needs to
record the user name running it. Is there a way for the program to extract
the name from the system without a separate log-in dialog?

Bob Parnes
What about:

import os
username = os.getlogin()

Please see other functions at:

http://docs.python.org/lib/os-procinfo.html

Best,

Laci 2.0



--
_________________________________________________________________
Laszlo Nagy web: http://designasign.biz
IT Consultant mail: (e-mail address removed)

Python forever!
 
L

Laszlo Zsolt Nagy

how about:



'gromit'
Hmm, yours is better. It also works on Windows. :)
I wonder why os.getuser() does not work in Windows - apparently there is
a good implementation for Windows.

--
_________________________________________________________________
Laszlo Nagy web: http://designasign.biz
IT Consultant mail: (e-mail address removed)

Python forever!
 
G

Gerhard Haering

I have a python program on a server of an all-linux network. It needs to
record the user name running it. Is there a way for the program to extract
the name from the system without a separate log-in dialog?

os.environ["USER"] for a start?

os.getuid() will give you the user id, but I don't know if Python has
methods to look up more information from that from /etc/passwd or
whereever from.

-- Gerhard

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)

iD8DBQFCCLwjdIO4ozGCH14RAna5AJ4+3aXhW2lnI87f6q6N1K/PzJMaqACfR4y3
Z9XqBXW0RpKyAoRYdW7qGtE=
=63xm
-----END PGP SIGNATURE-----
 
?

=?ISO-8859-1?Q?Michael_Str=F6der?=

Gerhard said:
os.getuid() will give you the user id, but I don't know if Python has
methods to look up more information from that from /etc/passwd or
whereever from.
('michael', 'x', 1234, 100, 'Michael Str\xf6der', '/home/michael',
'/bin/bash')
Ciao, Michael.
 
B

Bob Parnes

I have a python program on a server of an all-linux network. It needs to
record the user name running it. Is there a way for the program to extract
the name from the system without a separate log-in dialog?

Bob Parnes

Thanks very much. Had not realized there were so many possibilities.

Bob Parnes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top