Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: elevated privileges for a single call

by kcott (Chancellor)
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 #!/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";
$ Perl executing the script: /Users/ken/perl5/perlbrew/perls/perl-5.14.2 +_WITH_THREADS/bin/perl Script being executed: /Users/ken/tmp/ 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

Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1032473]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2018-06-22 01:27 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (120 votes). Check out past polls.