XY problem?

Do you really need to know what came on the left hand side of "perl" on the command line, or is your goal to determine whether you're running as a particular user, with certain permissions, or do you need to know if you're running with different real and effective user or group ID's?

For what it's worth, when operating under 'sudo', the environment variable $ENV{USER} will contain the login of the person who invoked sudo, and $ENV{SUDO_USER} will contain the login of the sudo target user (typically root, unless configured for some other user or otherwise specified). Sudo does set both real and effective uid and gid to the target user/group, so it wouldn't do any good detecting a mismatch there. But by detecting the USER adn SUDO_USER mismatch, you can detect sudo's effects.

So you could just check for the existence of $ENV{SUDO_USER}, or possibly, for $ENV{USER} and $ENV{SUDO_USER} to disagree. If either of those cases occur, you're probably running under sudo.

('probably', unless someone went to the trouble of tampering with those variables -- though I can't think of any reason why someone might.)


Dave


In reply to Re: Problem in command line arguements by davido
in thread Problem in command line arguements by firearm12

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.