Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: elevated privileges for a single call

by kcott (Abbot)
on May 07, 2013 at 12:27 UTC ( #1032473=note: print w/ replies, xml ) Need Help??


in reply to elevated privileges for a single call

G'day adalby,

Welcome to the monastery.

See perlvar for special variables that capture the type of information you're after. Here's a quick example with $^X, $0 and $$:

$ cat fred.pl #!/usr/bin/env perl use Cwd qw{abs_path}; print "Perl executing the script: ", `which $^X`; print "Script being executed: ", abs_path($0), "\n"; print "PID: $$\n";
$ fred.pl Perl executing the script: /Users/ken/perl5/perlbrew/perls/perl-5.14.2 +_WITH_THREADS/bin/perl Script being executed: /Users/ken/tmp/fred.pl PID: 33980

Variables relating to permissions include: $< (real user id), $> (effective user id), $( (real group id), $) (effective group id).

The English module provides longer, more meaningful names for these punctuation variables. Don't forget to load it as:

use English qw{-no_match_vars};

You might also find perlsec to be useful (even if only for additional examples using these special variables).

-- Ken


Comment on Re: elevated privileges for a single call
Select or Download Code
Re^2: elevated privileges for a single call
by adalby (Initiate) on May 07, 2013 at 16:21 UTC

    Thanks, Ken.

    That gives me info on MY executing program. I need info on a different program.

    To be specific, this is part of a script to monitor Oracle databases. Oracle can be installed multiple times on a server in multiple ORACLE_HOMEs. Each home can have zero or more running instances. I am trying to match the instances with the homes. Using the ps system call combined with grep I can find the PIDs of all the running instances. However, the cmd listed is just the basename, not the full path. WHICH doesn't help, since that just tells me the first exe resolved based on my PATH environment variable, not the particular copy that is executing. On Linux, the full path of executing processes are softlinked under /proc/$PID/exe. However, only the process owner and root can resolve the target of that link. I can sudo readlink (as in my script), but to do it in a shell script is ugly and/or AWKward. I would prefer to do it in perl, but I don't know how to sudo the readlink() function call.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1032473]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (9)
As of 2014-09-16 10:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (7 votes), past polls