Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-19 12:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found