Last active
July 11, 2016 05:04
-
-
Save mtk-f/0a835db742e605a100b0243814454b87 to your computer and use it in GitHub Desktop.
短縮URLのリンク先を調べる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/bash | |
tmp=/tmp/$$ | |
function getLocation() { | |
curl -I --silent $1 | while read line | |
do | |
if [[ "$line" =~ ^HTTP ]]; then | |
echo $line > $tmp-status | |
fi | |
if [[ "$line" =~ ^[Ll]ocation: ]]; then | |
echo $line > $tmp-location | |
fi | |
done | |
if [ ! -e $tmp-location ]; then | |
echo $1 | |
return | |
fi | |
location=$(echo $(cat $tmp-location) | sed -e "s/^[Ll]ocation: \?//") | |
rm -f $tmp-location | |
status=$(cat $tmp-status) | |
rm -f $tmp-status | |
if [[ "$status" =~ ^HTTP/.*\.*.*\ 30. ]]; then | |
getLocation $location | |
return | |
fi | |
echo $location | |
} | |
getLocation $1 | |
rm -f $tmp-* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment