Last active
September 12, 2019 19:25
-
-
Save eduardoaugustojulio/dda9573268b791809945de3372ff17d6 to your computer and use it in GitHub Desktop.
A script that runs simultaneously a curl GET command and returns the http status code of a list of addresses.
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
#!/bin/bash | |
readonly ARGC=$# | |
readonly ARGV=( "$@" ) | |
readonly PROG_NAME=$(basename "$0") | |
usage() | |
{ | |
echo "Usage: $PROG_NAME <url-list>" | |
exit 1 | |
} | |
gather_addresses() | |
{ | |
local file="$1" | |
local addresses=() | |
while read -r address ; | |
do | |
addresses+=( "$address" ) | |
done < "$file" | |
echo "${addresses[@]}" | |
} | |
curl_it() | |
{ | |
local url="$1" | |
local cmd="curl "$url"" | |
$cmd | |
} | |
parallel_curl() | |
{ | |
export -f curl_it | |
local addresses="$1" | |
parallel curl_it :::: $addresses | |
} | |
main() | |
{ | |
if [ "$ARGC" -gt 0 ] ; | |
then | |
local file | |
for file in $ARGV ; | |
do | |
[[ -f "$file" ]] && parallel_curl $file | |
done | |
else | |
usage | |
fi | |
} | |
main | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment