Skip to content

Instantly share code, notes, and snippets.

@janschumann
Created February 27, 2019 19:55
Show Gist options
  • Save janschumann/e844bdb584d4d9bb6b3cf69d47ba300d to your computer and use it in GitHub Desktop.
Save janschumann/e844bdb584d4d9bb6b3cf69d47ba300d to your computer and use it in GitHub Desktop.
Execute command in multiple directories in parallel
#!/bin/bash
# example: run puppet tests in all modules
CMD="pdk test unit --format=junit:report.xml &> pdk_test.log"
for d in $(ls -d); do {
cd $d
$CMD & pid=$!
PID_LIST+=" $pid";
cd ..
} done
trap "kill $PID_LIST" SIGINT
echo "Parallel processes have started";
wait $PID_LIST
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment