使用带有ONE脚本的多个命名选项卡在命名屏幕会话中启动多个脚本? [Debian的]

时间:2016-03-05 22:38:39

标签: linux bash shell gnu-screen

嗨,大家好我有点问题。

Nkay让我解释一下 我有3个Directorys,有3个不同的启动脚本。

user/dir1/launch1.sh

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

如果我像这样使用它,它会创建会话和第一个选项卡。但它冻结了,什么也没做。

1 个答案:

答案 0 :(得分:0)

这不干净(根本不是)但它有效。

~/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)