启动脚本以运行分离的屏幕,切换用户并运行多个bash命令

发布于 2025-02-09 11:45:20 字数 462 浏览 0 评论 0原文

我想创建一个小型启动脚本,该脚本在屏幕中连续进行多件事。

  1. 该脚本启动了一个指定的,独立的屏幕(屏幕-S discordbot -d -m works)
  2. 脚本中的用户被更改(都不是屏幕-S discordbot -x discordbot -x“ su discordbot” ,屏幕-s discordbot -x su discordbot,nor 屏幕-s discordbot -d -m bash -c“ su discordbot;”似乎至少可以subsqeuent命令未执行)。
  3. CD文件夹更改被视为更改。
  4. 启动了Java Jar或其他脚本。

当我运行多个机器人时,该脚本需要连续多次进行轻微的变化。关于如何做到这一点的任何指示?

I want to create a small startup script that does multiple things in a row in a screen.

  1. The script starts a named, detached screen (screen -S discordbot -d -m works)
  2. The user inside the script is changed (Neither screen -S discordbot -X "su discordbot", screen -S discordbot -X su discordbot, nor screen -S discordbot -d -m bash -c "su discordbot;" seems to work, or at least subsqeuent commands are not executed).
  3. A cd folder change is exectuded.
  4. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

疾风者 2025-02-16 11:45:20

您启动的屏幕会话将在启动退出的过程后立即退出。

例如,这有效:

$ screen -S discordbot -d -m bash
$ screen -ls
There is a screen on:
    2948.discordbot (Detached)
1 Socket in <...>

正如这样:

$ screen -S discordbot -d -m bin/discordbot.sh

其中bin/discordbot.sh看起来像这样:

#!/bin/sh

echo "Sleeping..."
sleep 10
/bin/echo -n "Hit enter to finish this script: "
read

最后两行,以防止屏幕过早退出。假设您以root的速度执行此操作,那么您想在该启动脚本中要做的其他各种事情也应该有效,以便su可以在不提示的情况下工作。

The screen session that you start up will exit as soon as the process that you started exits.

This works, for instance:

$ screen -S discordbot -d -m bash
$ screen -ls
There is a screen on:
    2948.discordbot (Detached)
1 Socket in <...>

As does this:

$ screen -S discordbot -d -m bin/discordbot.sh

Where bin/discordbot.sh looks like this:

#!/bin/sh

echo "Sleeping..."
sleep 10
/bin/echo -n "Hit enter to finish this script: "
read

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 the su will work without prompting.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文