How can I find out the original username a process was started with?

Posted by szabgab on Stack Overflow See other posts from Stack Overflow or by szabgab
Published on 2010-03-14T11:15:15Z Indexed on 2010/03/14 11:25 UTC
Read the original article Hit count: 224

Filed under:
|
|
|
|

There is a perl script that needs to run as root but the we must make sure the user who runs the script did not log-in originally as user foo as it will be removed during the script.

So how can I find out if the user, who might have su-ed several times since she logged in has not impersonated 'foo' at any time in that chain?

I found an interesting perl script that was calling the following two shell scripts, but I think that would only work on Solaris.

my $shell_paren = 
`ps -ef | grep -v grep | awk \'{print \$2\" \"\$3}\' | egrep \"^@_\" | awk \'{print \$2}'`;

my $parent_owner = 
`ps -ef | grep -v grep | awk \'{print \$1\" \"\$2}\' | grep @_ | awk \'{print \$1}\'`;

This needs to work on both Linux and Solaris and I'd rather eliminate the repeated calls to he the shell and keep the whole thing in Perl.

© Stack Overflow or respective owner

Related posts about perl

Related posts about shell