我想要做以下几件事:搜索结果
-
执行多个shell脚本(这里是2脚本)兼任。
-
等待两个脚本完成
-
转储每个脚本的返回值
然而, main.sh 不能按预期工作。
结果
main.sh #!/斌/庆典RET1 =`/ a.sh`和放大器。RET2 =`/ b.sh`如果[$ {} RET1=-a$ {} RET2=];然后 睡眠1其他 回声$ {} RET1,$ {} RET2结束a.sh
#!/斌/庆典睡眠10回音1b.sh
#!/斌/庆典睡眠5回音2解决方案
如果您有GNU并行 HTTP://www.gnu .ORG /软件/并口/ 安装,你可以这样做:
平行-j0'{};回声$? ::: a.sh b.sh我要退出code,检查其中的一个失败的怀疑,那你其实并不关心什么precise退出code了。在这种情况下,你可以这样做:
平行-j0 ::: a.sh b.sh ||呼应一方或双方的失败如果它足以获得失败的最后的误差code:
平行-j0 --halt 1 ::: a.sh b.sh;回声$?也许你想干掉a.sh如果b.sh年初完成,但失败:
平行-j0 --halt 2 ::: a.sh b.sh;回声$?您可以安装GNU并行只需:
wget的git.savannah.gnu/cgit/parallel.git/plain/src/parallel行chmod 755并行CP并行SEM留意GNU并行,以了解更多的介绍视频:www.youtube/playlist?list=PL284C9FF2488BC6D1
I want to do the following things:
Execute multiple shell scripts (here 2 scripts) concurrently.
Wait until both scripts finish
Dump return value of each script
However, main.sh does not work as expected.
main.sh #!/bin/bash ret1=`./a.sh` & ret2=`./b.sh` if [ "${ret1}"="" -a "${ret2}"="" ]; then sleep 1 else echo ${ret1},${ret2} enda.sh
#!/bin/bash sleep 10 echo 1b.sh
#!/bin/bash sleep 5 echo 2解决方案
If you have GNU Parallel www.gnu/software/parallel/ installed you can do this:
parallel -j0 '{}; echo $?' ::: a.sh b.shI have a suspicion that you want the exit code to check if one of them failed, and that you actually do not care what the precise exit code was. In that case you can do:
parallel -j0 ::: a.sh b.sh || echo one or both of them failedIf it is sufficient to get the error code of the last that failed:
parallel -j0 --halt 1 ::: a.sh b.sh; echo $?Maybe you would like to kill a.sh if b.sh finishes early but fails:
parallel -j0 --halt 2 ::: a.sh b.sh; echo $?You can install GNU Parallel simply by:
wget git.savannah.gnu/cgit/parallel.git/plain/src/parallel chmod 755 parallel cp parallel semWatch the intro videos for GNU Parallel to learn more: www.youtube/playlist?list=PL284C9FF2488BC6D1
更多推荐
执行多个shell脚本同时
发布评论