Created
June 4, 2018 00:21
-
-
Save justin808/67276efe955b2a44a5489444807332ed to your computer and use it in GitHub Desktop.
Simple bash script to run multiple tasks concurrently
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Edit the list of commands. | |
# YOU MUST USE SINGLE QUOTES HERE. | |
commands=( | |
'yarn run build:client-bundles:prod' | |
'yarn run build:server-bundle:prod' | |
'yarn run build:global-styles:prod' | |
) | |
################################################################################ | |
# DO NOT TOUCH BELOW THIS LINE | |
################################################################################ | |
pids="" | |
# Run concurrent processes | |
for command in "${commands[@]}"; do | |
echo command is ${command} | |
( ${command} ) & | |
pid=$! | |
# store PID of process | |
pids+=" ${pid}" | |
echo "${pid}: Running: ${command}" | |
done | |
# Wait for all processes to finnish, will take max 14s | |
for p in $pids; do | |
if wait $p; then | |
echo "Process $p succeeded." | |
else | |
echo "Process $p failed. Build aborted." | |
echo "Killing any running concurrent commands." | |
kill $pids &> /dev/null | |
exit 1 | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i want to use another variable in "commands"
like -> read -p "Enter your name: " name
commands=(
'echo "your name is $name" '
)