linux - screen GNU 脚本 Bash

标签 linux bash scripting gnu-screen

我想编写一个脚本,在我启动 PC 时自动执行我的任务。 主要思想是使用 screen 来完成它。 我写了这个,但它不起作用。只有它建立了第一个 session ,然后仅此而已。 这是代码

#!/bin/bash
screen -dmS angular sh -c 'cd Documents/segdet; ng serve --env=local'
screen -dmS jboss1 sh -x -c 'cd Documents/keycloak-2.3.0.Final/bin; ./standalone.sh -Djboss.socket.binding.port-offset=100 -b 0.0.0.0 &' 
screen -dmS jboss2 sh -x -c 'cd Documents/wildfly-10.1.0.Final/bin; ./standalone.sh -b 0.0.0.0 &' 

最佳答案

您需要使用 screen 的 -d 选项让 screen session 在启动后断开连接,以便它将移动到脚本中的下一个 session 。

还可以使用 -S 来命名 session ,以便您稍后可以连接到正确的 session 。

像这样:

#!/bin/bash
screen -dmS angular sh -c 'cd Documents/file1; ng serve --env=local' 
screen -dmS jboss1 sh -x -c 'cd Documents/file2/bin; ./standalone.sh -Djboss.socket.binding.port-offset=100 -b 0.0.0.0 &' 
screen -dmS jboss2 sh -x -c 'wil' 'cd Documents/file3/bin; ./standalone.sh -b 0.0.0.0 &'

这将启动 3 个名为 angular、jboss1 和 jboss2 的 screen session

关于linux - screen GNU 脚本 Bash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46122793/

相关文章:

c - 在 makefile 的帮助下编译后权限被拒绝

bash - 正确对齐列的 Shell 脚本

regex - 使用 grep 分割字符串的 shell 脚本

bash - 如何将变量中包含的多个值插入到 json 字符串中

windows - 删除 powershell 中的子目录,包括符号链接(symbolic link)

linux - 找不到 ttyUSB[id]

linux - 如何解决 EC2 上的 JIRA 安装问题?

r - 如何在基于rstudio ubuntu上轻松切换R版本?

bash - Windows批量输出换行女性字符

regex - 如何在 bash 中使用变量进行 grep