所以我有这个函数,我希望这个函数同时运行它本身包含的所有内容。到目前为止,它不起作用,根据其他消息来源,这就是你的做法。如果函数不是并行的,则函数本身可以工作。
#!/bin/bash
foo () {
cd ${HOME}/sh/path/to/script/execute
for f in *.sh; do #goes to "execute" directory and executes all
#scripts the current directory "execute" basically run-parts without cron
cd ~/sh/path/to/script
while IFS= read -r l1 #Line 1 in master.txt
IFS= read -r l2 #Line 2 in master.txt
IFS= read -r l3 #Line 3 in master.txt
do
cd /dev/shm/arb
echo ${l1} > arg.txt & echo ${l2} > arg2.txt & echo ${l3} > arg3.txt
cd ${HOME}/sh/path/to/script/execute
bash -H ${f} #executes all scripts inside "execute" folder
cd ~/sh/path/to/script/here
./here.sh &
cd ~/sh/path/to/script &
done <master.txt
done
}
export -f foo
parallel ::: foo
结果在
#No result at all....., just buffers. htop doesn't acknowledge any
#processes, and when this runs its pretty taxing on the cores.
主.txt内容
如果相关:
apple_fruit
apple_veggie
veggie_fruit
#apple changes
pear_fruit
pear_veggie
veggie_fruit
#pear changes
cucumber_fruit
...
我对使用并行很陌生,不知道它在高级(和基本(情况下是如何工作的,所以循环会干扰吗?如果它确实干扰,是否有解决方法?
结果可能是这样的:
inner() {
script="$1"
parallel -N3 "'$script' {}; here.sh {}" :::: master.txt
}
export -f inner
parallel inner ::: ${HOME}/sh/path/to/script/execute/*.sh
这将调用${HOME}/sh/path/to/script/execute/
(和here.sh
(中的每个脚本,其中包含 3 个参数master.txt
如下所示:
${HOME}/sh/path/to/script/execute/script1.sh apple_fruit apple_veggie veggie_fruit
您需要更改脚本,以便:
- 它们从命令行获取参数(而不是从
arg.txt
、arg2.txt
、arg3.txt
获取参数(。 - 他们将输出发送到标准输出