|
Download GUI Web Change Monitor script set. This GUI wrapper for UpdateWebURL.sh makes it very easy to monitor a set of web pages for change. GUIUpdateWebURL.sh will monitor as many web URLs for change as you want it to, and you can start, and stop monitoring URLs by pointing, and clicking for the most part. GUIUpdateWebURL.sh has one dependency, and that is it needs the package Xdialog installed for all of it's GUI widgets which this script uses. To install Xdialog issue the following command in Terminal. sudo apt-get install xdialog To use the script, simply download the .zip file, and unzip the script files in it into a folder somewhere in your user folder structure. Call the script from a menu entry with a command line like the following. /home/username/folder/path/GUIUpdateWebURL.sh GUI Web Change Monitor consists of three scripts, the main GUI providing script, the web page checking script, and a script to stop all running instances of the web page checking script should you decide to use it in command line mode only. The third script is not really needed for GUI Web Change Monitor to function correctly. This script set will make a /logs folder in whichever folder you run it from, and keeps daily log files of it's activities which rotate at midnight each night to the new day's log file. These log files are named DDMMYYYY.log, with the DDMMYYYY being the actual date the log was created on. This script uses UpdateWebURL.sh to do the actual checking of web pages for change, and has the ability to start, and stop those scripts. You may of course at any time start an instance of UpdateWebURL.sh on the command line yourself, and this script will still be able to stop it from running. You can in fact start several instances of UpdateWebURL.sh on the command line without even starting GUI Web Change Monitor, then start GUI Web Change Monitor to manage those already running instances. Here is the source code for GUIUpdateWebURL.sh
#!/usr/bin/env bash
#
# This is a GUI wrapper script for UpdateWebURL.sh which makes the process of monitoring web pages for change
# much easier.
#
# USAGE: /home/username/folder/path/GUIUpdateWebURL.sh
#
# Replace the username, folder, and path with the actual path to this script on your system.
# You may put the call to this script in a menu entry, or Sessions start up entry, and run it from there.
#
# This function allows the user to select a log file to view.
function SelectLogFile {
# Prompt user to choose a log file to open.
FileName=`Xdialog --auto-placement --stdout --title "Web Change Monitor - Select Log File to Open" --no-buttons --fselect "$DirectoryName/logs/*" 0 0`
# test for Cancel, or X button click.
ReturnValue=$?
case $ReturnValue in
1) # Cancel clicked, do nothing
return;;
255) # X button clicked, do nothing
return;;
esac
# get log file name for title bar
LogName=`basename $FileName`
# Load selected log file into text box.
Xdialog --auto-placement --title "Web Change Monitor - Log File Viewer - $LogName" --textbox "$FileName" 30 70 &
}
# This function loads today's log file into a tail box for viewing.
function ViewCurrentLog {
# get today's date for the daily log name.
today=$(date +%d%m%Y)
# load today's log file into a tail box to view the most recent entries.
Xdialog --auto-placement --title "Web Change Monitor - Current Log Entries - $today.log" --tailbox "$DirectoryName/logs/$today.log" 30 70 &
}
#
function LoadURLList {
while read Line; do
Time=$(date +%H:%M:%S)
echo "$Time Began Monitoring $Line" >> "logs/$today.log"
echo " " >> "logs/$today.log"
AddRecentURL $Line
# monitor the url on this line of the file. Execute in the background.
$DirectoryName/UpdateWebURL.sh $Line $Interval &
# pause so the log file does not get scrambled by two processes at the same time.
sleep 10
done < SavedURLList.txt
# Notify user that all urls have been loaded, and are now being monitored.
Xdialog --auto-placement --title "Web Change Monitor - URL List Loaded" --msgbox "Saved list of URLs loaded, and now being monitored." 0 0 &
}
# This function appends each url from the front half of each line from URLsMonitored.txt to the SavedURLList.txt file.
function BuildSavedList {
echo $1 >> SavedURLList.txt
}
# This function saves currently monitored URL list to SavedURLList.txt
function SaveURLList {
# Remove old SavedURLList.txt file so we can create a new one.
rm -f SavedURLList.txt
# initialize SavedURLList.txt file.
touch SavedURLList.txt
while read Line; do
# Feed this line of CurrentURLs.txt to the parameter stripper to rid the line of the PID.
BuildSavedList $Line
done < CurrentURLs.txt
# notify user that file has been saved.
Xdialog --auto-placement --title "Web Change Monitor - URL List Saved" --msgbox "URL list has been saved to SavedURLList.txt" 0 0 &
}
# This function stops one URL from being monitored, and is called by StopMonitoringAll().
function StopURL {
Time=$(date +%H:%M:%S)
echo "$Time Stopped Monitoring $1" >> "logs/$today.log"
echo " " >> "logs/$today.log"
# kill the process with PID passed in as $2
kill $2
# remove temporary files this script was using
rm -f "$DirectoryName/$2$2.html"
rm -f "$DirectoryName/$2.html"
}
# This function stops all URL monitoring.
function StopMonitoringAll {
# test to see of CurrentURLs.txt exists, and if it does not exit this function
if [ -e "$DirectoryName/CurrentURLs.txt" ]
then
echo "nothing" >null
else
return
fi
# loop through CurrentURLs.txt, and stop all running UpdateWebURL.sh instances.
while read Line; do
# if $Line not equal to "", if this line is not empty due to no urls being monitored at this time.
if [ "$Line" != "" ]
then
# Stop the script instance from this line of the file.
StopURL $Line
fi
done < "$DirectoryName/CurrentURLs.txt"
# Remove old CurrentURLs.txt file since we are now monitoring nothing
rm -f "$DirectoryName/CurrentURLs.txt"
# and initialize it to an empty file to prevent problems with StopMonitoringURL finding no file to read
touch "$DirectoryName/CurrentURLs.txt"
# Notify the user that we have have stopped monitoring all URLs.
Xdialog --auto-placement --title "Web Change Monitor - Stopped Monitoring" --msgbox "All URL monitoring has been stopped." 0 0 &
}
# This function retrieves the PID of the script instance monitoring URLtoMatch, and writes a temporary
# file with all of the lines that did not match URLtoMatch.
function MatchURLforPID {
# If URLtoMatch is equal to the passed in lines web url
if [ "$URLtoMatch" == "$1" ]
then # grab the PID off of the line
PIDMatched="$2"
else
# write non-matching lines to tmp.txt
echo "$1 $2" >> "$DirectoryName/tmp.txt"
fi
}
# Allows user to stop monitoring one URL.
function StopMonitoringURL {
PIDMatched=""
URLList=""
# build list of urls currently being monitored from CurrentURLs.txt
while read Line; do
BuildList $Line
done < CurrentURLs.txt
# if the built list is empty
if [ "$URLList" == "" ]
then
# tell the user there are no instances of the script to stop.
Xdialog --auto-placement --title "Web Change Monitor - Monitoring Idle" --msgbox "There are no URLs being monitored currently." 0 0 &
else
# present user with a drop down list of urls to choose from for stopping.
URLtoMatch=`Xdialog --auto-placement --stdout --title "Web Change Monitor - Stop Monitoring URL" --combobox "Select URL to discontinue monitoring from the drop down list." 10 60 $URLList`
# test for cancel or X button click.
ReturnValue=$?
case $ReturnValue in
1) # Cancel clicked
return;;
255) # X button clicked
return;;
esac
touch "$DirectoryName/tmp.txt"
# fetch PID of script monitoring that URL
while read Line; do
MatchURLforPID $Line
done < CurrentURLs.txt
# Stop the process with the matched PID.
Time=$(date +%H:%M:%S)
echo "$Time Stopped Monitoring $URLtoMatch" >> "logs/$today.log"
echo " " >> "logs/$today.log"
kill "$PIDMatched"
# write new shorter CurrentURLs.txt
rm CurrentURLs.txt
cat "$DirectoryName/tmp.txt" > CurrentURLs.txt
rm -f "$DirectoryName/tmp.txt"
# Remove temporary files that instance of the script was using.
rm -f "$DirectoryName/$PIDMatched$PIDMatched.html"
rm -f "$DirectoryName/$PIDMatched.html"
fi
}
# This function builds up a list of urls to use in a combo box.
function BuildList {
# concatenate $1 (web site url) from each line to the URLList variable.
URLList="$URLList $1"
}
# This function loads and begins monitoring one recently loaded URL from RecentURLs.txt
function LoadRecentURL {
# Check to see if there are any recent URLs to load.
if [ -e "$DirectoryName/RecentURLs.txt" ]
then
echo "nothing" >null
else
Xdialog --auto-placement --title "Web Change Monitor - No Recent URLs" --msgbox "There are no recent URLs in the Recent URLs list." 0 0 &
return
fi
URLList=""
# build list of recent urls from RecentURLs.txt
while read Line; do
# remove PID from $Line, and add the URL portion of $Line to URLList.
BuildList $Line
done < RecentURLs.txt
# if the list of URLs is blank, tell the user, and exit function, otherwise give user a list of URLs to choose from.
if [ "$URLList" == "" ]
then
Xdialog --auto-placement --title "Web Change Monitor - No Recent URLs" --msgbox "There are no recent URLs in the Recent URLs list." 0 0 &
return
else
# present user with a drop down list of urls to choose from for monitoring.
URLtoLoad=`Xdialog --auto-placement --stdout --title "Web Change Monitor - Recent URLs Selection" --combobox "Select URL to monitor from the drop down list." 10 60 $URLList`
# test for cancel or X button click.
ReturnValue=$?
case $ReturnValue in
1) # Cancel clicked
return;;
255) # X button clicked
return;;
esac
# Begin monitoring recently used $URLtoLoad
Time=$(date +%H:%M:%S)
echo "$Time Begin Monitoring $URLtoLoad" >> "logs/$today.log"
echo " " >> "logs/$today.log"
$DirectoryName/UpdateWebURL.sh $URLtoLoad $Interval &
fi
}
# Add URL to recently loaded URLs list. Recently loaded URLs list holds up to 30 recent URLs.
function AddRecentURL {
# create RecentURLs.txt if it didn't exist already
touch "$DirectoryName/RecentURLs.txt"
# Detect if this URL is already in ths recent URLs list, and return if it is.
while read Line; do
# Compare new URL to this line
if [ "$1" == "$Line" ]
then # if a match is found exit this function.
return
fi
done < "$DirectoryName/RecentURLs.txt"
# initialize LineCounter
URLCount=0
# count the lines in the recent URLs list.
while read Line; do
# Count lines in the file
(( URLCount +=1 ))
done < "$DirectoryName/RecentURLs.txt"
# create temporary file to write new lines to
touch "$DirectoryName/temp.txt"
if [ $URLCount == 20 ]
then
# Write all lines except the first one from RecentURLs.txt to tmp.txt
LineCount=0
while read Line; do
(( LineCount +=1 ))
if [ "$LineCount" == "1" ]
then # do nothing
echo "Nothing to do" >null
else # add line to temp.txt
echo "$Line" >> "$DirectoryName/temp.txt"
fi
done < "$DirectoryName/RecentURLs.txt"
else # write entire file to temp.txt
while read Line; do
echo "$Line" >> "$DirectoryName/temp.txt"
done < "$DirectoryName/RecentURLs.txt"
fi
# write most recent url to temp.txt
echo "$1" >>"$DirectoryName/temp.txt"
# over write RecentURLs.txt with new list of recent URLs
cat temp.txt >"$DirectoryName/RecentURLs.txt"
# remove temporary file
rm -f "$DirectoryName/temp.txt"
}
#
function MonitorURL {
# Prompt user to enter a valid web url to monitor.
WebURL=`Xdialog --auto-placement --stdout --title "Web Change Monitor - Begin Monitoring URL" --inputbox "Type or paste in a valid URL of the form htttp://www.somesite.com/folder/path/filename.ext?query" 0 0`
# test for cancel or X button click.
ReturnValue=$?
case $ReturnValue in
1) # Cancel clicked
return;;
255) # X button clicked
return;;
esac
# test that url starts with http:// or a number, or something else inappropriate.
case "$WebURL" in
http://*)
# Add URL to recent URLs List
AddRecentURL $WebURL
Time=$(date +%H:%M:%S)
echo "$Time Begin Monitoring $WebURL" >> "logs/$today.log"
echo " " >> "logs/$today.log"
# begin monitoring the new url.
$DirectoryName/UpdateWebURL.sh $WebURL $Interval &;;
https://*)
# Add URL to recent URLs List
AddRecentURL $WebURL
Time=$(date +%H:%M:%S)
echo "$Time Begin Monitoring $WebURL" >> "logs/$today.log"
echo " " >> "logs/$today.log"
# begin monitoring the new url.
$DirectoryName/UpdateWebURL.sh $WebURL $Interval &;;
[0-9]*)
Xdialog --auto-placement --title "Web Change Monitor - Malformed URL" --msgbox "Please enter a url of the form \n http://www.somesite.com/folder/path/filename.ext?query" 0 0 &
MonitorURL;;
*)
Xdialog --auto-placement --title "Web Change Monitor - Malformed URL" --msgbox "Please enter a url of the form \n http://www.somesite.com/folder/path/filename.ext?query" 0 0 &
MonitorURL;;
esac
}
# Main Program Starts Here.
today=$(date +%d%m%Y);
# set default time interval for web checks.
Interval=300
# Get current working directory
DirectoryName=`dirname $0`
cd "$DirectoryName"
# Initialize MenuChoice
MenuChoice=""
while [ "$MenuChoice" != "Exit" ]
do
# Show main menu, and branch on user selections.
MenuChoice=`Xdialog --auto-placement --stdout --no-tags --title "Web Change Monitor - Main Menu" --cancel-label "Exit" --menubox "Please make a selection below." 18 60 4 "AdjustInterval" "Adjust Timeout Interval Between Checks" "Monitor" "Begin Monitoring a New Web URL" "Recent" "Load Recent URL for Monitoring" "StopURL" "Stop Monitoring One URL" "StopAll" "Stop Monitoring All URLs" "SaveList" "Save List of Currently Monitored URLs to File" "LoadList" "Load and Begin Monitoring Saved URL List" "ViewLog" "View Current Log File Entries" "SelectLog" "Select a Log File to View" "Exit" "Exit Web Change Monitor"`
ReturnValue=$?
# trap whether or not cancel was pressed
case $ReturnValue in
1) # Cancel clicked
# Stop monitoring all web urls.
StopMonitoringAll
# Remove temporary files used by scripts.
rm -f "$DirectoryName/go.txt"
rm -f "$DirectoryName/CurrentURLs.txt"
exit;;
255) # X button clicked
# Stop monitoring all web urls.
StopMonitoringAll
# Remove temporary files used by scripts.
rm -f "$DirectoryName/go.txt"
rm -f "$DirectoryName/CurrentURLs.txt"
exit;;
esac
case $MenuChoice in
"AdjustInterval")
Interval=`Xdialog --auto-placement --stdout --title "Web Change Monitor - Set Interval" --spinbox "Set the spinner to the number of seconds you want for the timeout interval." 0 0 30 3600 300 "Seconds"`;;
"Monitor")
MonitorURL &;;
"Recent")
LoadRecentURL &;;
"StopURL")
StopMonitoringURL &;;
"StopAll")
StopMonitoringAll;;
"SaveList")
SaveURLList;;
"LoadList")
LoadURLList &;;
"ViewLog")
ViewCurrentLog;;
"SelectLog")
SelectLogFile &;;
"Exit")
StopMonitoringAll
rm -f "$DirectoryName/go.txt"
rm -f "$DirectoryName/CurrentURLs.txt"
exit;;
esac
done
![]() Here is a screen capture of the Main Menu for GUI Web Change Monitor. ![]() The first menu entry is "Adjust Time Interval Between Checks". When you select it, you are presented with a spinner dialog which allows you to select an interval from 30 seconds to 3600 seconds to wait between web page checks for change. To change the time interval for all web checks, fist use the "Save List of Currently Monitored URLs to File", then "Stop Monitoring All URLs". Now select the Timeout Interval menu item, and set the interval to what you want. Now use "Load and Begin Monitoring Saved URL List" to restart monitoring of all of your saved URLs with the new timeout interval in force. ![]() The menu entry "Begin Monitoring a New Web URL" will allow you to type, or paste in one valid URL to monitor. The only paste methods supported are CTRL-V, and clicking the scroll wheel on your mouse, as Xdialog does not support context menus. ![]() The menu entry "Load Recent URL for Monitoring", will present you with up to 20 recently monitored URLs in a drop down list to select one from, to begin monitoring again. Each time you use "Begin Monitoring a New Web URL" the URL gets saved to a text file which will not grow beyond 20 lines of URLs. ![]() The menu entry "Stop Monitoring One URL" will allow you to stop one URL from being monitored any longer. When you select it, you will be presented with a drop down list of all URLs currently being monitored to choose from. ![]() The menu entry "Stop Monitoring All URLs" has no user prompts, and simply stops all instances of UpdateWebURL.sh from running. It does pop up a message box to tell you that all web URL monitoring has been stopped. ![]() The menu entry "Save List of Currently Monitored URLs to File" has no user prompts either. It saves a list of all of the currently being monitored web URLs to a text file for reloading later, with the next menu entry "Load and Begin Monitoring Saved URL List". This menu entry has no user prompts either, but both of the menu entries do pop up a message box to tell you they have completed their tasks. The menu entry "View Current Log File Entries" loads today's log file into a tail box which runs in the background, and updates as new log entries hit the log file. You may click the Cancel button, or the title bar X button at any time on any dialog in Web Change Monitor to back out of a menu selection you have made without taking any action. Clicking the Exit, or title bar X buttons on the main menu will exit the program, and discontinue monitoring all web URLs. The menu entry "Select Log File to View" opens a file open dialog in the scripts /logs folder where you can select any date's log file for viewing in a text box. You can use this menu entry to load and view any text file on your system, but it is mainly for viewing the Web Change Monitor log files. The last menu entry "Exit Web Change Monitor", and the Exit button, as well as the title bar X button will all exit Web Change Monitor, and discontinue monitoring all web URLs. Whenever an instance of UpdateWebURL.sh detects that a web page has changed since the last time it was checked, it will load that web page into your default web browser on your system for viewing. Note that some sites like Face Book change constantly, so you will have it loading into your browser every time it gets checked as it is never the same two times in a row. Download GUI Web Change Monitor script set. Help me keep writing code for others to use. Please consider making a donation of whatever you can afford if you use my scripts, even something as small as one dime would help a lot. Thanks. |
|
| Last modified on: |