Skip to content

Instantly share code, notes, and snippets.

@madoke
Last active December 15, 2015 17:49
Show Gist options
  • Save madoke/5299584 to your computer and use it in GitHub Desktop.
Save madoke/5299584 to your computer and use it in GitHub Desktop.
Tails a remote file via HTTP. Polls the HTTP Headers, via curl, and when "Content-Length" has changed, fetches the remaining difference
#!/bin/bash
POLLING_INTERVAL=2
CONTENT_LENGTH=0
while true
do
FETCH_CONTENT_LENGTH=`curl -s -r 0-0 -I $1 | egrep -i "Content-Range" | cut -d/ -f2 | awk -F"\r" '{print $1}'`
TMP_CONTENT_LENGTH=$FETCH_CONTENT_LENGTH
if [[ $TMP_CONTENT_LENGTH > $CONTENT_LENGTH ]]
then
if [[ $CONTENT_LENGTH == 0 ]]
then
curl -s -r -500 $1
else
REMAINING=$CONTENT_LENGTH-$TMP_CONTENT_LENGTH
curl -s -r $REMAINING $1
fi
CONTENT_LENGTH=$TMP_CONTENT_LENGTH
fi
sleep $POLLING_INTERVAL
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment