Find Current User in Linux

This is the place for queries that don't fit in any of the other categories.

Find Current User in Linux

Postby deadsoul2 » Fri Dec 27, 2013 7:43 pm

Hello,

I have a redhat linux and I am trying to find the logged in username via python script

Ex: I always login with Bret login ID and then sudo to root

Now - Using python script - I want to find the real login name not the one after sudo.

so, Bret should be the answer of the script.

Please help.
Last edited by Yoriz on Fri Dec 27, 2013 7:53 pm, edited 1 time in total.
Reason: First post lock
deadsoul2
 
Posts: 2
Joined: Fri Dec 27, 2013 7:39 pm

Re: Find Current User in Linux

Postby Yoriz » Fri Dec 27, 2013 7:53 pm

Try this
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Image
User avatar
Yoriz
 
Posts: 1056
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Re: Find Current User in Linux

Postby deadsoul2 » Sun Dec 29, 2013 2:31 pm

Hello,

Thanks for the reply.

This is the first time - I am interacting with Python.

Can you help me exactly what is the command or syntex to type in ? pls
deadsoul2
 
Posts: 2
Joined: Fri Dec 27, 2013 7:39 pm

Re: Find Current User in Linux

Postby rrashkin » Sun Dec 29, 2013 2:57 pm

Code: Select all
 import os
 os.getlogin()
  'root'
 
___________________
Bob Rashkin
User avatar
rrashkin
 
Posts: 35
Joined: Tue Feb 12, 2013 4:47 pm


Return to General Coding Help

Who is online

Users browsing this forum: micseydel, snippsat and 4 guests