Created
June 20, 2015 08:14
-
-
Save vyper/359bd472973bf84e7079 to your computer and use it in GitHub Desktop.
Looping in parallel using bash
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
function wait_run_in_parallel() | |
{ | |
local number_to_run_concurrently=$1 | |
if [ `jobs -np | wc -l` -gt $number_to_run_concurrently ]; then | |
wait `jobs -np | head -1` | |
fi | |
} | |
function get_status() { | |
local line=$1 | |
id=$(echo $line | cut -d ' ' -f 1) | |
url=$(echo $line | cut -d ' ' -f 2) | |
status=$(curl -s -I $url | head -n 1 | gsed -E "s/HTTP\/1.1 ([0-9]+) .*/\1/") | |
echo "${id} => ${url} => ${status}" | |
} | |
while read line | |
do | |
get_status "$line" & | |
wait_run_in_parallel 50 | |
done | |
wait |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
e lendo faz todo o sentido do mundo... dá aquela sensação... "como não pensei nisso?"