[英]Running a file as nonroot from a root bash script
Okay, I currently use an eggdrop IRC bot on my server. 好的,我目前在服务器上使用Eggdrop IRC bot。 I want to make a bash script to start it up as well as a few other scripts at the same time.
我想制作一个bash脚本以及其他一些脚本来同时启动。 All that's left is to make it start, but it won't run as root.
剩下的就是让它启动,但是不会以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 例如:/ home / eggdrop / eggdropbot / eggdrop将显示错误,因此要运行它,我需要先CD / home / eggdrop / eggdropbot然后cd./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. 因此,我不能只使用“ sudo -u eggdrop / home / eggdrop / eggdropbot / eggdrop”,并且您可能知道,sudo也不会cd,因为那将毫无意义。
Any suggestions? 有什么建议么?
Why not just cd
first and then sudo -u ./eggdrop .
为什么不先先
cd
然后再sudo -u ./eggdrop .
? ?
What about doing the cd
, and, only then, launch the command with sudo
? 怎样做
cd
,然后才用sudo
启动命令?
I suppose something like this should do the trick : 我想这样的事情应该可以解决:
cd /home/eggdrop/eggdropbot && sudo -u eggdrop ./eggdrop
您可以以root用户身份cd
到目录,然后使用sudo -u
从工作目录中调用程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.