-1

I have a Python script lets call it foo.py and I need to execute this first. After this script is finished executing I have to run about 10 Java JAR files (lets call it waldo.jar). I want to save time and have them run concurrently. How do I replicate this function in a shell script?

I have this so far:

#!/bin/bash
cd /root
python3 foo.py 1> output.txt
java -jar waldo.jar fooArg barArg & # Jar 1
java -jar waldo.jar fooArg2 barArg2 & # Jar 2
java -jar waldo.jar fooArg3 barArg3 & # Jar 3
... and so on
echo "All Finished!"

I need those jar files running at the same time in the background.

user1757703
  • 2,925
  • 6
  • 41
  • 62

1 Answers1

0

right before the end, you can add the following to wait for all child processes to finish.

echo "[$(date '+%Y-%m-%d %H:%M:%S')] Waiting for subprocesses..";
for job in `jobs -p`
do
    echo $job
    wait $job
done
Fabricator
  • 12,722
  • 2
  • 27
  • 40