Paralell猛砸内运行串行 [英] Run Serial inside Paralell Bash
问题描述
我已经加入到我的解释了一下。从概念上讲,我是运行在一个循环处理,称使用该行的内容作为输入参数炮弹的脚本(供参考:一揭开序幕执行和B监视执行)。
I have added to my explanation a bit. Conceptually, I am running a script that processes in a loop, calling shells that use the line content as an input parameter.(FYI: a kicks off an execution and b monitors that execution)
- 我需要1a和1b先运行,在paralell前两个$参数
- 接下来,2a和2b必须以串行运行$ PARAMS当步骤1完成
- 3a和3b将揭开序幕,一旦2a和2b是完整的(如果不相关的串行或并行)
- 循环继续从输入下一个2线的.txt
我不能让它处理第二个串行,只有所有并行:我需要的是以下
I cant get it to process the second in serial, only all in parallel: What I need is the following
cat filename | while readline
export param=$line
do
./script1a.sh "param" > process.lg && ./script2b.sh > monitor.log &&
##wait for processes to finish, running 2 in parallel in script1.sh
./script2a.sh "param" > process2.log && ./script2b.sh > minitor2.log &&
##run each of the 2 in serial for script2.sh
./script3a.sh && ./script3b.sh
我尝试添加在观望,并试图含有script2a.sh和script2b.sh将串行运行一个if语句,但无济于事。
I tried adding in wait, and tried an if statement containing script2a.sh and script2b.sh that would run in serial, but to no avail.
if ((++i % 2 ==0)) then wait fi
done
#only run two lines at a time, then cycle back through loop
我如何在地球上可以得到script2.sh以串行运行在平行SCRIPT1的结果?
How on earth can I get the script2.sh to run in serial as a result of script1 in parallel??
推荐答案
您没有向我们展示了如何从文件中读取行被消耗。结果
如果我没有理解你的问题,你要在平行于文件名
,每两条线运行 SCRIPT1
,然后连续运行 SCRIPT2
两者都完成后?
You are not showing us how the lines you read from the file are being consumed.
If I understand your question correctly, you want to run script1
on two lines of filename
, each in parallel, and then serially run script2
when both are done?
while read first; do
echo "$first" | ./script1.sh &
read second
echo "$second" | ./script1.sh &
wait
script2.sh & # optionally don't background here?
script3.sh
done <filename &
的,而
循环包含两个读
语句,所以每次迭代从读两行文件名
每个供稿 SCRIPT1
的一个单独的实例。然后我们等
,直到我们都运行之前完成<$ C $ C> SCRIPT2 。我的背景是这样 script3
可以同时运行启动和背景整个,而
循环;但你可能实际上并不需要后台默认整个作业(如果你写它作为一个经常前台作业,那么当它工作,背景,当您启动它,如果你需要将整个事情的发展会容易得多)。
The while
loop contains two read
statements, so each iteration reads two lines from filename
and feeds each to a separate instance of script1
. Then we wait
until they both are done before we run script2
. I background it so that script3
can start while it runs, and background the whole while
loop; but you probably don't actually need to background the entire job by default (development will be much easier if you write it as a regular foreground job, then when it works, background the whole thing when you start it if you need to).
我能想到一些关于这个变化,这取决于你如何真正希望自己的数据流;这里是为了应对最近更新的问题的最新情况。
I can think of a number of variations on this depending on how you actually want your data to flow; here is an update in response to your recently updated question.
export param # is this really necessary?
while read param; do
# First instance
./script1a.sh "$param" > process.lg &&
./script2b.sh > monitor.log &
# Second instance
read param
./script2a.sh "$param" > process2.log && ./script2b.sh > minitor2.log &
# Wait for both to finish
wait
./script3a.sh && ./script3b.sh
done <filename
如果这仍然没有帮助,也许你应该张贴的第三的问题,你居然真的解释你想要什么...
If this still doesn't help, maybe you should post a third question where you really actually explain what you want...
这篇关于Paralell猛砸内运行串行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!