testing if a script is run via sudo

U

Une Bévue

Is tehre a way to test if a ruby script is run as a sudoer user ?

For the time being i'm using a zsh script to test that however I'd like
using ruby only.

the zsh i'm using :
#! /usr/bin/env zsh

[ "$SUDO_USER" -a `id -u` -eq 0 ] || {
echo "false"
exit 0
}
echo "true"
exit 0
 
R

Rahul Kumar

Une said:
Is tehre a way to test if a ruby script is run as a sudoer user ?

on my system, echo $USER gives root under sudo (mac os x).

So in ruby:

ENV['USER']

will return root under sudo user, and my name normally.

Note that here i have done a "sudo bash" first.
 
B

Brian Candler

Une said:
Is tehre a way to test if a ruby script is run as a sudoer user ?

$ sudo ruby -e "require 'etc'; puts Process.uid, Process.euid,
Etc.getlogin"
0
0
brian

... so I'm running as root, but I originally logged in as brian.
 
A

Ammar Ali

2010/10/7 Une B=C3=A9vue said:
Is tehre a way to test if a ruby script is run as a sudoer user ?

A cleaner way would be to use the=C2=A0Process::UID module, namely the #eid=
method.

HTH
Ammar
 
U

Une Bévue

Rahul Kumar said:
on my system, echo $USER gives root under sudo (mac os x).

So in ruby:

ENV['USER']

will return root under sudo user, and my name normally.

Note that here i have done a "sudo bash" first.

I'm using too Mac OS X (zsh as default shell) i don't get samething as u
:

imyt% sudo echo $USER
Password:
yt
imyt% echo $USER
yt
imyt%


however "yt" -is- a sudoer...
 
U

Une Bévue

Brian Candler said:
$ sudo ruby -e "require 'etc'; puts Process.uid, Process.euid,
Etc.getlogin"
0
0
brian

.. so I'm running as root, but I originally logged in as brian.

i see, nice !
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top