I'm writing a bash script which has many parts, but I want built in resiliency and parallel processing as much as possible. An example is below:
while true do var=$(curl someurl) || continue var2=$(curl someurl2) || continue var3=$(curl someurl3) || continue dosomething var1 || continue dosomething2 var2 || continue dosomething3 var3 || continue break done
I'd like to run the 3 curl commands in parallel, and then the three "do something" commands in parallel as well. However, I'm not sure how this would be handled. I considered inserting the
wait command after each block and inserting
& after each command as follows:
while true do var=$(curl someurl) & || continue var2=$(curl someurl2) & || continue var3=$(curl someurl3) & || continue wait dosomething var1 & || continue dosomething2 var2 & || continue dosomething3 var3 & || continue wait break done
However, in this situation, I'm not sure how the exit statuses and/or race conditions could be managed. Additionally, this doesn't seem like best coding practices. Is there a good way to do this?