For Programmers: Free Programming Magazines  


Home > Archive > Ruby > August 2005 > getuid









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author getuid
Leslie Viljoen

2005-08-28, 6:59 pm

Hello everyone!

I am struggling to detect in a script whether the current user is root or
not. Etc.getlogin seems to return my unpriveleged username even after
I have done an 'su' or run the script with 'sudo' to become root.

All I really need is:

if Etc.getuid != 0
puts "You are not root"
exit
end



--
ruby -e "puts 'Just another fickle programmer'"

Leslie Viljoen [leslie@camary.co.za]
Camary Consulting [http://www.camary.co.za]
Cellphone [083-6186100]
Personal web [http://mobeus.homelinux.org]




Bruce Woodward

2005-08-28, 6:59 pm

irb(main):004:0> if Process.euid !=3D 0
irb(main):005:1> puts "you are not root"
irb(main):006:1> end
you are not root
=3D> nil


On 8/25/05, Leslie Viljoen <leslie@camary.co.za> wrote:
> Hello everyone!
>=20
> I am struggling to detect in a script whether the current user is root or
> not. Etc.getlogin seems to return my unpriveleged username even after
> I have done an 'su' or run the script with 'sudo' to become root.
>=20
> All I really need is:
>=20
> if Etc.getuid !=3D 0
> puts "You are not root"
> exit
> end
>=20
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com