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
In reply to Re: Obtaining userid from script called by sudo and other scripts
by Eliya
in thread Obtaining userid from script called by sudo and other scripts
by njetson
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |