gpt4 book ai didi

linux - 使用一个脚本在具有多个命名选项卡的命名 screen session 中启动多个脚本? [ Derby 安]

转载 作者:太空宇宙 更新时间:2023-11-04 12:55:38 25 4
gpt4 key购买 nike

大家好,我有一个小问题。

让我解释一下我有 3 个目录和 3 个不同的启动脚本。

user/dir1/launch1.s​​h

user/dir2/launch2.sh

user/dir3/launch2.sh

user/startall.sh

我如何构建脚本以使用 startall 脚本启动所有 3 个启动脚本,以便:

每个脚本都有自己的 Tap?

到目前为止我的尝试:

#!/bin/bash
echo "Create Screen"
screen -AdmS Screenname -t Console bash
echo "Start htop"
screen -S Screenname -x screen -t Performance htop
echo "Start Script 1"
screen -S Screenname -x screen -t Tab1 ./dir1/launch1.sh
echo "Start Script 2"
screen -S Screenname -x screen -t Tab2 ./dir2/launch2.sh
echo "Start Script 3"
screen -S Screenname -x screen -t Tab3 ./dir3/launch3.sh

如果我这样使用它,它会创建 session 和第一个选项卡。但随后它卡住并且什么都不做。

最佳答案

这(一点也不干净)但它有效。

~/dir/script.sh

echo "killing scripts"
killall -9 python #kill all open python processes
echo "start 1"
cd /logs/1 #dir change so files from .py go to correct location
screen -md -S 1 python /logs/1/1.py #start 1.py in a screen named 1
echo "start 2"
cd /logs/2 #dir change so files from .py go to correct location
screen -md -S 2 python /logs/2/2.py #start 2.py in a screen named 2
echo "start 3"
cd /logs/3 #dir change so files from .py go to correct location
screen -md -S 3 python /logs/3/3.py #start 3 in a screen named 3
echo "sleeping"
#use screen -list to view running screens
#screen -x user/1 to see the screen named 1 etc
#(personally I use 1 terminator window split x 8 to view 8 different python scripts)
#killall at start of script is because of thread hanging in my py script
#i crontab script.sh every hour (this is what the killall is for at the start of the
#script, so the previous runs processes don't eat processes)
#if you do not want to use killall -9 python, because of other running python scripts
#replace it with "pkill -f 1.py" for example, (pkill only takes one 'pattern'
#so each target needs its own line, so 3 lines of pkill to kill 1 2 3.py)

关于linux - 使用一个脚本在具有多个命名选项卡的命名 screen session 中启动多个脚本? [ Derby 安],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35820784/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com