启动脚本以运行分离的屏幕,切换用户并运行多个bash命令
我想创建一个小型启动脚本,该脚本在屏幕中连续进行多件事。
- 该脚本启动了一个指定的,独立的屏幕(
屏幕-S discordbot -d -m
works) - 脚本中的用户被更改(都不是
屏幕-S discordbot -x discordbot -x“ su discordbot” ,
屏幕-s discordbot -x su discordbot
,nor屏幕-s discordbot -d -m bash -c“ su discordbot;”
似乎至少可以subsqeuent命令未执行)。 CD
文件夹更改被视为更改。- 启动了Java Jar或其他脚本。
当我运行多个机器人时,该脚本需要连续多次进行轻微的变化。关于如何做到这一点的任何指示?
I want to create a small startup script that does multiple things in a row in a screen.
- The script starts a named, detached screen (
screen -S discordbot -d -m
works) - The user inside the script is changed (Neither
screen -S discordbot -X "su discordbot"
,screen -S discordbot -X su discordbot
, norscreen -S discordbot -d -m bash -c "su discordbot;"
seems to work, or at least subsqeuent commands are not executed). - A
cd
folder change is exectuded. - A java jar or other script is started.
As I run multiple bots, the script needs to be able to do this in slight variation multiple times in a row. Any pointers on how this could be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您启动的屏幕会话将在启动退出的过程后立即退出。
例如,这有效:
正如这样:
其中
bin/discordbot.sh
看起来像这样:最后两行,以防止屏幕过早退出。假设您以
root
的速度执行此操作,那么您想在该启动脚本中要做的其他各种事情也应该有效,以便su
可以在不提示的情况下工作。The screen session that you start up will exit as soon as the process that you started exits.
This works, for instance:
As does this:
Where
bin/discordbot.sh
looks like this:The last two lines to prevent the screen from exiting prematurely. The other various things you want to do within that startup script should also work, assuming that you do this as
root
so that thesu
will work without prompting.