Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1492
  • Last Modified:

Perl/Tk Check is user is root

Hello again,

I have a shell script that I am converting to Perl which is used in my Perl/Tk application. It's such a simple script, that I have wasted hours failing clearly lists me for the Darwin awards. I need to check if a user is root, and if not, list that he needs root privileges before continuing. What I have that does not work is:

my $user = `whoami`;
my $uid = getpwnam("$user"); # this is not working as I would expect
if ("$uid" != 0)
{
   print "You must be root Ian! You obtuse moron!!!\n);
}

My god this is so simple in shell script, how can I be screwing it up so badly???

Thanks for any thoughts!

Ian
0
DesertShark2
Asked:
DesertShark2
  • 2
1 Solution
 
mrjoltcolaCommented:
Try the Perl builtin variable,   $<

0
 
mrjoltcolaCommented:
Sorry, to explain, it is the UID of the user.
0
 
DesertShark2Author Commented:
Wow, my Perl book did not make this ~that~ easy.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now