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
···
--
« Comment peser sur le bulletin?
Tu t'assieds dessus. »
(Anonyme)
R_Kumar
(R. Kumar)
2
Une Bévue wrote:
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.
···
--
Posted via http://www.ruby-forum.com/\.
Une Bévue wrote:
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.
···
--
Posted via http://www.ruby-forum.com/\.
A cleaner way would be to use the Process::UID module, namely the #eid method.
HTH
Ammar
···
2010/10/7 Une Bévue <unbewusst.sein@fai.invalid>
Is tehre a way to test if a ruby script is run as a sudoer user ?
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...
···
Rahul Kumar <sentinel1879@gmail.com> wrote:
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.
--
« Comment peser sur le bulletin?
Tu t'assieds dessus. »
(Anonyme)