in reply to Obtaining userid from script called by sudo and other scripts
If you don't trust the environment variable SUDO_USER, you could also walk the process tree upward until you find your answer.
--MidLifeXis