in reply to Obtaining userid from script called by sudo and other scripts

Not sure I understand your script nesting problem, but as for sudo, the environment variable SUDO_USER (set by sudo to who called sudo) might help.

$ sudo -u nobody perl -E 'say scalar getpwuid $>; say $ENV{SUDO_USER}' nobody eliya

Replies are listed 'Best First'.
Re^2: Obtaining userid from script called by sudo and other scripts
by njetson (Initiate) on Feb 14, 2012 at 22:29 UTC
    the SUDO_USER variable solved the problem: Thank you