我想编写一个脚本,在我启动 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/