Skip to content

Instantly share code, notes, and snippets.

@kalmas
Forked from thetristan/diff_url
Last active June 26, 2017 16:12
Show Gist options
  • Save kalmas/bb7ebd5db1c6b9fd31cc4a902e2d37bd to your computer and use it in GitHub Desktop.
Save kalmas/bb7ebd5db1c6b9fd31cc4a902e2d37bd to your computer and use it in GitHub Desktop.
Diff the response from 2 or more URLs.
#!/bin/bash
# Diff the JSON response from 2 or more URLs.
name=`basename $0`
if [ $# -lt 3 ]
then
echo "Usage: $NAME <path> <host 1> <host 2> <...>" 1>&2
echo "Example: $NAME /foo https://www.example.com https://www.google.com https://www.amazon.com" 1>&2
exit 1
fi
path=$1
shift
index=0
diff_cmd="diff -wu --from-file"
for host in "$@"
do
url="${host}${path}"
file="/tmp/diff_urls.file.${index}"
# cURL resource and sort JSON response
curl_cmd="curl -s $url | jq -SM '.' > $file"
echo "$curl_cmd" 1>&2
bash -c "$curl_cmd"
diff_cmd+=" $file"
index=$((index+1))
done
# Diff all temp files.
echo "$diff_cmd"
bash -c "$diff_cmd"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment