[英]Running shell script only if parallel backgrounded scripts complete successfully
我有4個bash腳本:
script1.sh
script2.sh
script3.sh
wrapper.sh
我希望script1.sh和script2.sh在后台運行。 script1.sh和script2.sh應該同時運行(即使script1.sh失敗,script2.sh也應該運行,反之亦然)。 我希望script3.sh僅在script1.sh和script2.sh成功完成時運行。
wrapper.sh腳本應該運行所有3個腳本。
我怎樣才能實現它?
您可以像這樣使用warpper.sh
:
#!/bin/bash
# execute script1.sh in background and save pid in $pid1
./script1.sh &
pid1=$!
# execute script2.sh in background and save pid in $pid2
./script2.sh &
pid2=$!
# do more work here...
# wait for both background jobs to finish and save their return status
wait $pid1 && wait $pid2 && ./script3.sh
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.