Skip to content

Instantly share code, notes, and snippets.

@spyesx
Last active June 13, 2018 11:15
Show Gist options
  • Save spyesx/e6314d0ac98b4b39755618b75f3f901e to your computer and use it in GitHub Desktop.
Save spyesx/e6314d0ac98b4b39755618b75f3f901e to your computer and use it in GitHub Desktop.
Webpage monitor

Webpage monitor

Monitors a web page for changes every 30min then sends an email notification if the file changes.

Start

Start with nohup

nohup sh webpage_monitor.sh > nohup.log 2>&1 &

Get PID

echo $! > save_pid.txt

Read live log

tail -f nohup.log

Kill process

kill `cat save_pid.txt`
rm save_pid.txt
Hello,
This page has changed:
https://www.domain.tld/example/of/a/url/
See yah !
#!/bin/bash
# Monitors a web page for changes every 30min
# sends an email notification if the file change
URL="https://www.domain.tld/example/of/a/url/"
SEARCH="element to observe"
while true; do
mv new.html old.html 2> /dev/null
curl $URL -L --compressed -s | grep -c "$SEARCH" > new.html
DIFF_OUTPUT="$(diff new.html old.html)"
if [ "${#DIFF_OUTPUT}" != "0" ]; then
mail -s "Mail subject" [email protected] < message.txt
fi
sleep 30m
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment