#!/bin/sh basedir="$(cd $(dirname $0); pwd)" set -e file=urls-test.txt if [ "$1" ] ; then file="$1" fi if [ ! -d har-data ]; then mkdir har-data ; fi cat $file | while read url ; do case "$url" in http*) # Save with URL as filename, replacing / with % and dropping trailing slash. filename=$(echo "$url" | sed 's%/$%%' |tr / %) harfile="har-data/$filename.har" if [ ! -e "$harfile" ] ; then echo "testing $url" if phantomjs --ssl-protocol any $basedir/netsniff.js "$url" > "$harfile.new" && [ -s "$harfile.new" ]; then mv "$harfile.new" "$harfile" else if ! rm "$harfile.new" ; then echo "error: unable to remove $harfile.new" fi fi else echo "info: not contacting "$url", already had $harfile" fi ;; esac done