0

I am trying to run two scripts in the background. However I would like to have one script run first, wait for it to finish and run the next script recursively. Will this code snippet do as such:

for i in "${studyinstanceuids[@]}"
do
#let count="$count+1"
echo "$i" | ./cmd2&
sleep 5
if job1 is alive then sleep 5
      echo "$i" | ./sendExamToRepo.sh&
      wait
fi
BMW
  • 42,880
  • 12
  • 99
  • 116

1 Answers1

0
for i in "${studyinstanceuids[@]}"; do
    ( echo "$i" | ./cmd2; echo "$1" | ./sendExamToRepo.sh )&
done
wait
DopeGhoti
  • 757
  • 7
  • 15
  • What this does is, for each iteration of `i`, run the first command followed by the second command in sequence, in the background. Which is to say, each pair is run in order, but all pairs' first commands will run more or less in parallel. See the test case [here](http://sprunge.us/ZeZO?sh). For a clearer picture, add a `sleep` to `thing2`. – DopeGhoti Feb 12 '14 at 00:40
  • ahh ok, because the bigger part of the script reads from a txt file that grabs files (with whats written in the txt file) and uploading them to my server (process 1) and sends them to another server (process 2) i hope that each process can be executed recursively until my script finishes reading from the txt file and grabbing files –  Feb 12 '14 at 00:47