Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check for root when a user runs a perl script

Tags:

perl

root

I am working a script to generate a config file that I want to store in /etc/solignis. When I run the script as a limited user it does not allow me to create the directory or write the file. So the script will have to run as sudo or a root user, how can I check if the user is a root or atleast using sudo?

like image 664
ianc1215 Avatar asked Mar 12 '11 04:03

ianc1215


2 Answers

If $> (aka $EFFECTIVE_USER_ID if you use English) is non-zero, then the user is not root.

like image 170
cjm Avatar answered Jan 01 '23 07:01

cjm


XAppSoftware: How to check for root user has a solution:

my $login = (getpwuid $>);
die "must run as root" if $login ne 'root';
like image 33
Sonia Hamilton Avatar answered Jan 01 '23 07:01

Sonia Hamilton