Skip to content

Instantly share code, notes, and snippets.

@tonejito
Created March 27, 2014 05:13
Show Gist options
  • Save tonejito/9800785 to your computer and use it in GitHub Desktop.
Save tonejito/9800785 to your computer and use it in GitHub Desktop.
Fetch resource following all Location headers, setting the apropriate referer and saving all the cookies
#!/bin/bash -vx
#
# ./follow-curl.sh
# Fetch resource following all Location headers and setting the apropriate referer and saving all the cookies
#
# Andres Hernandez - tonejito
# Released under the BSD license
#
CAT=cat
CURL=curl
MKTEMP=mktemp
function help()
{
echo "
Usage: ${0} <URL> [<cookie>]
<URL>: URL to be downloaded
<cookie>: cURL's cookie jar filename
" ;
}
if [ -n "${1}" ]
then
URL=${1}
else
help;
exit 1;
fi
if [ -n "${2}" ]
then
COOKIE=${2}
else
COOKIE=`$MKTEMP --tmpdir=.`
fi
$CURL -vk# --location --referer ';auto' -A '' --cookie $COOKIE --cookie-jar $COOKIE $URL
$CAT $COOKIE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment