Created
July 8, 2018 16:55
-
-
Save rms1000watt/65d2f1533b0852c3834fcbb69490abeb to your computer and use it in GitHub Desktop.
Batch Parallel cURL Download in Bash
This file contains hidden or 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 | |
| waitFor() { | |
| pids=$1 | |
| errs=() | |
| for pid in ${pids[@]}; do | |
| echo "wait $pid" | |
| wait $pid | |
| errs+=($?) | |
| done | |
| for err in ${errs[@]}; do | |
| echo "$err" | |
| done | |
| } | |
| pids=() | |
| curl "http://urlecho.appspot.com/echo?body=1111%0A" & pids+=($!) | |
| curl "http://urlecho.appspot.com/echo?body=2222%0A" $(sleep 2) & pids+=($!) | |
| curl "http://urlecho.appspot.com/echo?body=3333%0A" $(sleep 3) & pids+=($!) | |
| curl "http://urlecho.appspot.com/echo?body=4444%0A" & pids+=($!) | |
| curl "http://urlecho.appspot.com/echo?body=5555%0A" $(sleep 5) & pids+=($!) | |
| curl "http://urlecho.appspot.com/echo?body=6666%0A" & pids+=($!) | |
| waitFor $pids | |
| pids=() | |
| curl "http://urlecho.appspot.com/echo?body=1111%0A" & | |
| pids+=($!) | |
| curl "http://urlecho.appspot.com/echo?body=2222%0A" $(sleep 2) & | |
| pids+=($!) | |
| curl "http://urlecho.appspot.com/echo?body=3333%0A" $(sleep 3) & | |
| pids+=($!) | |
| curl "http://urlecho.appspot.com/echo?body=4444%0A" & | |
| pids+=($!) | |
| curl "http://urlecho.appspot.com/echo?body=5555%0A" $(sleep 5) & | |
| pids+=($!) | |
| curl "http://urlecho.appspot.com/echo?body=6666%0A" & | |
| pids+=($!) | |
| waitFor $pids |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment