在Unix上,如果发现谁执行的程序是root用户? [英] On Unix, find if user who executed the program is root?

查看:130
本文介绍了在Unix上,如果发现谁执行的程序是root用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个剧本耙,想检测(使用Ruby而不是bash的如果可能的话),如果谁执行耙脚本具有root权限的用户。

I'm writing a rake script and would like to detect (using Ruby rather than bash if possible) if the user who executed the rake script has root privileges.

如果它不是那么根,我想终止脚本。

If it is not root then I would like to terminate the script.

推荐答案

使用 UID EUID 过程 类:

Use uid or euid in the Process class:

raise 'Must run as root' unless Process.uid == 0

这篇关于在Unix上,如果发现谁执行的程序是root用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆