rawurlencode() {
  local string="${1}"
  local strlen=${#string}
  local encoded=""
  local pos c o

  for (( pos=0 ; pos<strlen ; pos++ )); do
     c=${string:$pos:1}
     case "$c" in
        [-_.~a-zA-Z0-9] ) o="${c}" ;;
        * )               printf -v o '%%%02x' "'$c"
     esac
     encoded+="${o}"
  done
  echo "${encoded}"    # You can either set a return variable (FASTER) 
  REPLY="${encoded}"   #+or echo the result (EASIER)... or both... :p
}
#Copy the existing Feed to a backup location
mv /var/www/html/useragentfeed.csv /var/www/html/useragentfeed.csv.bak
# First Get a list of UserAgents from our Broker. We are only concerned with those that are http traffic
#curl -s --user 'admin:netwitness' 'http://192.168.123.249:50103/sdk?msg=values&fieldName=client&where=service=80&size=2000' |grep field |cut -f 2 -d ">" |cut -d "<" -f1 >|>tmp/useragent.txt
curl -s --user 'admin:netwitness' 'http://192.168.123.249:50103/sdk?msg=values&fieldName=client&size=20000' |grep field |cut -f 2 -d ">" |cut -d "<" -f1 |grep -v rsyslogd | grep -v pts |grep -v ignored |grep -v \(\) >/tmp/useragent.txt
#For each UserAgent send it through our device detector Parser

while read p; do
  php -f script.php "$p" >>/var/www/html/useragentfeed.csv
done </tmp/useragent.txt
