Bash dropping out of sudo in a script

后端 未结 1 1580
误落风尘
误落风尘 2021-01-28 21:48

I need to execute an install script using sudo, but towards the end of the script, the script needs to drop out of sudo and continue as the regular user.

Example:

<
相关标签:
1条回答
  • 2021-01-28 22:07

    su myscriptuser starts another shell in the name of myscriptuser and waits until it exits. Then it proceeds to run service myscript start in the name of root again.

    What you need instead of the last 2 commands is sudo:

    sudo -u myscriptuser service myscript start
    
    0 讨论(0)
提交回复
热议问题