Created
October 17, 2022 08:14
-
-
Save tiagocoutinho/566f2e9978b261cccf7255d719bf5db7 to your computer and use it in GitHub Desktop.
Concurrent bash tasks
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
#!/bin/bash | |
[email protected]: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