Created
September 30, 2017 23:17
-
-
Save anonymous/60550f0ba3a7bf814f879da59bdb13f1 to your computer and use it in GitHub Desktop.
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 | |
FILE="$1" | |
while read -r LINE; do | |
# read the response to a variable | |
response=$(curl -H 'Cache-Control: no-cache' -s -i -k --max-time 2 --write-out '%{http_code} %{size_header} %{redirect_url} ' "$LINE") | |
# break the response in parts | |
headers=$(sed -n '1,/^\r$/p' <<<"$response") | |
content=$(sed -e '1,/^\r$/d' -e '$d' <<<"$response") | |
read -r http_code size_header redirect_url < <(tail -n1 <<<"$response") | |
# get the real Location | |
location=$(grep -oP 'Location: \K.*' <<<"$headers") | |
printf "***Url: %s\n\n" "$LINE" | |
printf "Status: %s\n\n" "$http_code" | |
printf "Size: %s\n\n" "$size_header" | |
printf "Redirect-url: %s\n\n" "$redirect_url" | |
printf "Title: %s\n\n" "$title" | |
# -c 20 only shows the 20 first chars from response | |
printf "Body: %s\n\n" "$(head -c 100 <<<"$response")" | |
done < "${FILE}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment