Created
July 29, 2016 09:51
-
-
Save teeli/4efb12ddce5c9b64a18b241ca14f04cc to your computer and use it in GitHub Desktop.
Watch a URL for changes and output the diff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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