473,383 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

User Identification

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

--
Bob Parnes
rp*****@megalink.net
Jul 18 '05 #1
6 1449
Bob Parnes wrote:
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:
import getpass
getpass.getuser()

'gromit'

</F>

Jul 18 '05 #2
Bob Parnes wrote:
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: ga*****@geochemsource.com

Python forever!
Jul 18 '05 #3
how about:
import getpass
getpass.getuser()

'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: ga*****@geochemsource.com

Python forever!
Jul 18 '05 #4
On Tue, Feb 08, 2005 at 12:29:48PM -0000, Bob Parnes wrote:
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-----

Jul 18 '05 #5
Gerhard Haering wrote:

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.

import pwd,os
pwd.getpwuid(os.getuid()) ('michael', 'x', 1234, 100, 'Michael Str\xf6der', '/home/michael',
'/bin/bash')


Ciao, Michael.
Jul 18 '05 #6
On Tue, 08 Feb 2005 12:29:48 -0000, Bob Parnes <rp*****@megalink.net> wrote:
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

--
Bob Parnes
rp*****@megalink.net
Jul 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

60
by: Fotios | last post by:
Hi guys, I have put together a flexible client-side user agent detector (written in js). I thought that some of you may find it useful. Code is here: http://fotios.cc/software/ua_detect.htm ...
5
by: Carl Ribbegaardh | last post by:
Is there any known list of compiler identification macros? I'm using VS 2003, g++ on windows, sun's cc and g++ on solaris. Is it possible to identify the compiler using macros? I'm aware of WIN32...
3
by: Zlatko Matić | last post by:
Excuse me, what is the difference between user and system_user and which function should be used in audit trail table ? Thanks.
23
by: Roel Melchers | last post by:
My ACCESS-database contains all members of my association. When the members attend to a meeting I want to record their presence. When they enter they identify themselves by putting their finger...
3
by: Caspy | last post by:
I just get stuck on how to check if a user is a member of network (domain). I am building an internal tracking system with ASP.Net with Form authentication. When an user is added into the system,...
2
by: suresh | last post by:
Hello to you all In my .Net application, I want to import document images (Tiff images), having same format, in a batch, For e.g. I have a document folder containing mixed images like...
2
by: John | last post by:
Help! I've just spend the last three days researching and testing the following issue without any results. I have a test page setup to get the Windows logon name of the user. The site is a...
18
by: Arthur | last post by:
Hi All, I would like to get the name of the user given their networkID, is this something Active Directory would be useful for?(For intranet users) If so, can you please point me to some sample...
4
by: shapper | last post by:
Hello, I am creating a Poll system and I need to check if a user has already voted. What should be the best way to do this? 1. Should I save the user IP along with its vote in the database?...
2
by: mitja | last post by:
Hi, I have read a lot of posts on the web and got no answer. Is there any chance of geting any unique client identification data (his IP-but not proxy IP or router or NAT, his username, his...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.