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

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?

Answers


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


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

my $login = (getpwuid $>);
die "must run as root" if $login ne 'root';

if ( $< != 0 ) {
print "This script must be run as root\n"; 
exit (0);
}

I had the same question and ended up using the results of all three previous answers:

die "Must run as root\n" if $> != 0;

Need Your Help

How can I prevent text displacement for some foreign language fonts?

actionscript-3 flash fonts internationalization text-rendering

I have a multilingual project (currently 13 languages), which uses many different font variations of "Helvetica Neue", mostly bold, condensed and regular cuts from the LinoType Pro font set ( which

npm WARN deprecated graceful-fs@3.0.8: graceful-fs version 3

javascript node.js npm bower

I am running npm install but it's giving me an error. I also tried to run below command before update. $npm install npm and also I updated graceful-fs.