I had a requirement to identify the actual user account and full name of the current user who was currently “Sued” to a higher privileged user account such as Oracle. The below script provides me with that functionality:
#!/usr/bin/python import pdb import os import sys import subprocess import commands import time import socket import locale locale.setlocale(locale.LC_ALL, 'en_US') user_name = os.popen("who am i| awk '{print $1}'").read() user_name=user_name.rstrip('\n') print user_name os.environ['py_user_name'] = user_name user_name = os.popen("cat /etc/passwd | grep ${py_user_name} | awk -F \":\" '{print $5}'").read() user_name=user_name.rstrip('\n') print user_name
(I may have extra imports as this was taken from a much larger script.)