从 root bash 脚本以非 root 身份运行文件
好的,我目前在我的服务器上使用 Eggdrop IRC 机器人。我想制作一个 bash 脚本来启动它以及同时启动其他一些脚本。剩下的就是让它启动,但它不会以 root 身份运行。
但是,我还需要在文件的当前目录中才能运行它,否则会显示错误。
例如: /home/eggdrop/eggdropbot/eggdrop 将显示错误,因此要运行它,我需要 cd /home/eggdrop/eggdropbot 然后 ./eggdrop
所以我不能只使用“sudo -u Eggdrop /home/eggdrop/eggdropbot/eggdrop”,而且你可能知道, sudo 也不会 cd,因为那样会毫无意义。
有什么建议吗?
Okay, I currently use an eggdrop IRC bot on my server. I want to make a bash script to start it up as well as a few other scripts at the same time. All that's left is to make it start, but it won't run as root.
However, I also need to be in the current directory of the file to run it, or it displays an error.
For example:
/home/eggdrop/eggdropbot/eggdrop will display an error, so to run it I need to
cd /home/eggdrop/eggdropbot and then ./eggdrop
So I can't just use "sudo -u eggdrop /home/eggdrop/eggdropbot/eggdrop" and as you probably know, sudo won't cd, either, since that would be pointless.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为什么不先
cd
然后sudo -u ./eggdrop .
?Why not just
cd
first and thensudo -u ./eggdrop .
?执行
cd
,然后使用sudo
启动命令怎么样?我想这样的事情应该可以解决问题:
What about doing the
cd
, and, only then, launch the command withsudo
?I suppose something like this should do the trick :
您可以以root 用户身份
cd
进入该目录,然后使用sudo -u
从工作目录调用程序。You can
cd
to the directory as the root user and then usesudo -u
to invoke the program from the working directory.