[EMAIL PROTECTED] wrote:
Hi all. How can I check, within a script, to see if it is being run as root
or not? I would like it to exit with an error message if it is not running
as root. I'm looking for something that works across *nix platforms so that
my script is portable. Is there a perl function that does this or perhaps
checking the uid?
I looked at the USER in %ENV but that does not show as root when I su to
root. At least, not in FreeBSD.

perldoc perlvar [snip] $REAL_USER_ID $UID $< The real uid of this process. (Mnemonic: it's the uid you came from, if you're running setuid.) You can change both the real uid and the effective uid at the same time by using POSIX::setuid().

       $EFFECTIVE_USER_ID
       $EUID
       $>      The effective uid of this process.  Example:

                   $< = $>;            # set real to effective uid
                   ($<,$>) = ($>,$<);  # swap real and effective uid

               You can change both the effective uid and the real uid at the
               same time by using POSIX::setuid().

               (Mnemonic: it's the uid you went to, if you're running setuid.)
               $< and $> can be swapped only on machines supporting
               setreuid().


John -- use Perl; program fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to