Skip to content

Instantly share code, notes, and snippets.

@kimmellj
Last active December 21, 2015 20:09
Show Gist options
  • Save kimmellj/6359410 to your computer and use it in GitHub Desktop.
Save kimmellj/6359410 to your computer and use it in GitHub Desktop.
Demand Ware Web Tail
#!/bin/bash
POLLING_INTERVAL=2
CONTENT_LENGTH=0
URL=$1
USER=$2
PASS=$3
if [ -z "$URL" ]
then
echo "No Url was specified, please select a previously used url:"
a=0
while read line
do a=$(($a+1));
echo "$a) $line";
done < ".past_urls"
read selection
a=0
while read line
do a=$(($a+1));
if [[ "$a" == "$selection" ]]
then
URL=$line
fi
done < ".past_urls"
fi
if [ -z $USER ]
then
a=0
while read line
do a=$(($a+1));
case "$a" in
1)
USER=$line
;;
2)
PASS=$line
;;
esac
done < ".auth"
fi
if [ -z $URL ]
then
echo "URL? "
read URL
fi
if [ -z $USER ]
then
echo "Username? "
read USER
fi
if [ -z $PASS ]
then
echo "Password? "
read PASS
fi
echo $USER > .auth
echo $PASS >> .auth
USER="$(perl -MURI::Escape -e 'print uri_escape($ARGV[0]);' "$USER")"
PASS="$(perl -MURI::Escape -e 'print uri_escape($ARGV[0]);' "$PASS")"
ADDURL=true
while read line
do
if [[ "$line" == "$URL" ]]
then
ADDURL=false
fi
done < ".past_urls"
if $ADDURL;
then
echo "$URL" >> .past_urls
fi
if [ ! -z "$USER" -a "$USER" != " " ]
then
URL=${URL/\/\//\/\/$USER:$PASS@}
fi
echo "URL: $URL"
echo "USER: $USER"
echo "PASS: $PASS"
tail -10 .past_urls > .past_urls_tmp
mv .past_urls_tmp .past_urls
while true
do
FETCH_CONTENT_LENGTH=`curl -s -r 0-0 -I $URL | 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 $URL
else
REMAINING=$CONTENT_LENGTH-$TMP_CONTENT_LENGTH
curl -s -r $REMAINING $URL
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