Thursday, May 31, 2018

Simple Script To Monitor Web Page For Changes

#!/bin/bash
#***********************************************
#* Author: mmyrick
#* Date Created: 20180531
#* Purpose: Monitor a website for signs of change
#* Environment: Works from OSX v10.13.4
#************************************************

##THIS MUST BE SET MANUALLY
#Download Page, Hash Page, and Assign Original MD5
curr=f9a38facacc54241e4028bd2d2108a8b

#BEGIN ENDLESS LOOP
while true; do

#Download webpage
/usr/bin/curl -s -o /tmp/blah.txt www.purple.com

#Sleep for 5 seconds so page can download
/bin/sleep 5

#Hash the page
new=$(/sbin/md5 /tmp/blah.txt | cut -f4 -d " ")
#/bin/echo $new

#Compare the two MD5 values
if [[ "$new" != "$curr" ]]
then
 #PRINT ONLY IF Something Has Changed
 /bin/echo "THE WEBPAGE HAS CHANGED"
 /bin/echo "THE WEBPAGE HAS CHANGED"
 /bin/echo "THE WEBPAGE HAS CHANGED"
 /bin/echo "THE WEBPAGE HAS CHANGED"
 /bin/echo "THE WEBPAGE HAS CHANGED"
fi

#Remove temp files
/bin/rm /tmp/blah.txt

#Get WebPage Once Every 5 Min
/bin/sleep 300

#Run Again
done

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.