Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple bash script to run multiple tasks concurrently
#!/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