Skip to content

Instantly share code, notes, and snippets.

@tiagocoutinho
Created October 17, 2022 08:14
Show Gist options
  • Save tiagocoutinho/566f2e9978b261cccf7255d719bf5db7 to your computer and use it in GitHub Desktop.
Save tiagocoutinho/566f2e9978b261cccf7255d719bf5db7 to your computer and use it in GitHub Desktop.
Concurrent bash tasks
#!/bin/bash
BASE_URL=git@github.com:tiagocoutinho
REPOS=( "gepace" "cryocon" "vacuubrand" "xia-pfcu" "mythen-dcs" )
CLONE="git clone --depth=1 --no-single-branch"
function fetch {
for repo in "${REPOS[@]}"
do
echo "Start fetching $repo..."
$CLONE $BASE_URL/$repo
done
}
function fetch_background {
repos_urls=()
repos_pids=()
for repo in "${REPOS[@]}"
do
echo "Start fetching $repo..."
url="$BASE_URL/$repo/"
repos_urls[${#repos_urls[@]}]=$url
$CLONE -q $url &
repos_pids[${#repos_pids[@]}]=$!
done
for job in "${repos_pids[@]}"
do
wait $job
echo "Finished $job"
done
}
function fetch_parallel {
# --halt now,fail=1 exit when the first job fails. Kill running jobs.
parallel $CLONE $BASE_URL/{} ::: ${REPOS[@]}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment