#!/bin/bash # An example script for downloading files contained in an http_manifest.txt # file from the OBPG servers # # This script uses curl and assumes the http_manifest.tx file has been obtained # Usage: http_manifest_download_curl.bash http_manifest.txt # # If an error is encountered, the retrieved wget headers will be saved # as .header for inspection # LIST=$1 if [ -z "$LIST" ] then echo "No input file list supplied" exit 1 fi if [[ ! -a $LIST ]]; then echo "$LIST does not exist!" exit 1 fi COUNTER=1 for FILE in $(cat $LIST) do BASEFILE=`echo $FILE|cut -d / -f 6|cut -d \? -f 1` CHK=$(($COUNTER % 19)) curl --dump-header "${BASEFILE}.headers" -L -o $BASEFILE $FILE STATUS=$? echo "Grabbing $BASEFILE..." if [ $CHK -eq 0 ]; then if [ $COUNTER -gt 1 ]; then echo "pausing a couple seconds to take a breath..." sleep 2 fi fi if [ $STATUS -ne 0 ]; then ERRCODE=`grep "HTTP/" "${BASEFILE}.headers" | awk '{print $2}'` echo $ERRCODE if [ $ERRCODE -eq 503 ]; then while [ $STATUS -gt 0 ] do echo "pausing 10 seconds to take a breath..." sleep 10 curl --dump-header "${BASEFILE}.headers" --limit-rate 500k -L -o $BASEFILE $FILE STATUS=$? if [ $STATUS -ne 0 ]; then ERRCODE=`grep "HTTP/" ${BASEFILE}.headers | awk '{print $2}'` if [ $ERRCODE -ne 503 ]; then STATUS=-1 else STATUS=1 fi fi done fi fi if [ $STATUS == 0 ]; then rm -rf ${BASEFILE}.headers fi let COUNTER=COUNTER+1 done