Skip to content

Instantly share code, notes, and snippets.

@vyper
Created June 20, 2015 08:14
Show Gist options
  • Save vyper/359bd472973bf84e7079 to your computer and use it in GitHub Desktop.
Save vyper/359bd472973bf84e7079 to your computer and use it in GitHub Desktop.
Looping in parallel using bash
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
@marcocarvalho
Copy link

e lendo faz todo o sentido do mundo... dá aquela sensação... "como não pensei nisso?"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment