Skip to content

Instantly share code, notes, and snippets.

@teeli
Created July 29, 2016 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teeli/4efb12ddce5c9b64a18b241ca14f04cc to your computer and use it in GitHub Desktop.
Save teeli/4efb12ddce5c9b64a18b241ca14f04cc to your computer and use it in GitHub Desktop.
Watch a URL for changes and output the diff
#!/bin/bash
#
# This script checks if content in a specific URL has changed
# and shows the diff.
#
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
date=`date +%Y-%m-%d_%H:%M:%S`
echo "Starting process at $date in $dir"
filename="$dir/file.txt"
url="https://url.to/file.txt"
echo "Get url $url and write to $filename"
curl -s ${url}
echo "Get 2 newest files"
pattern="$dir/file*"
files=($(ls -t $pattern | head -2))
if [ ${#files[@]} -lt 2 ]; then
echo "Not enough files"
exit 1
fi
echo "Found more than 2 files, show diff"
diff ${files[0]} ${files[1]}
# remove old files
find $dir -mmin +120 -type f -name 'file*' -delete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment