On Unix, find if user who executed the program is root?

前端 未结 2 599
别那么骄傲
别那么骄傲 2021-02-18 13:54

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

2条回答
  •  感动是毒
    2021-02-18 14:14

    Use uid or euid in the Process class:

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

提交回复
热议问题