Help me keep writing code for others to use. Please consider making a donation of whatever you can afford if you use my scripts.
UPDATE: I have re-written PollWebSite.sh, and renamed it MonitorWebSite.sh in this version 1.15 of Web Site Monitor. The new script has the added capability of checking to insure that your Internet connection is up and running, if it fails to download the monitored file from your web sites, before telling you that your web site is down.
It it detects that your Internet connection is down, it warns you that your connection is not working, instead of telling you that your web site is down as it would have before.
This new Web Site Monitor script is a GUI wrapper script which calls MonitorWebSite.sh to do the actual monitoring of your web sites.
It makes the task of monitoring one, or more web sites, or individual URLs much easier than the command line version.
WebSiteMonitor.sh depends on the package Xdialog being installed on your system. Xdialog provides all of the GUI dialogs used by Web Site Monitor. To install Xdialog issue the following command in Terminal.
sudo apt-get install xdialog
You will be prompted for your password, then Xdialog will be installed on your system.
To use these scripts just download the tar.gz file, then decompress the files along with their folders onto your drive. Then issue the command "sudo /home/$USERNAME/.WebSiteMonitor/install.sh" from terminal, to install Web Site Monitor.
To run Web Site Monitor, simply issue the command WebSiteMonitor.sh in terminal, or add that command to a menu entry, and select the menu entry.
#!/usr/bin/env bash # # This is the GUI version of PollWebSite.sh called GUIPollWebSite.sh This version has # expanded capability over the command line version in that you may # start, and stop multiple web site polls from one interface, which allows adding, and removing web sites # to be moniitored more easily. # # This GUI version requires that you install the Xdialog package to gain the GUI capabilities of this # script. # ## Copyright: ## Copyright 2009 by C. Ray Parrish ## All Rights Reserved ## ## License: ## Released under the GNU General Public License (GPL) ## http://www.gnu.org/copyleft/gpl.html ## ## This program is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License ## as published by the Free Software Foundation; either version 3 ## of the License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## # Allow user to pick from recently used URLs, selecting one to monitor anew. function LoadRecentURLs { # Check to see if there are any recent URLs to load. if [ -e "$DirectoryName/RecentURLs.txt" ] then echo else # tell user there are none, and exit function. 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 Site 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 stopping. URLtoLoad=`Xdialog --auto-placement --stdout --title "Web Site 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 # get working directory for script MonitorWebSite.sh $URLtoLoad $Interval & fi } # Add URL to recently loaded URLs list. Recently loaded URLs list holds up to 20 recent URLs by default. # You can change how many recent URLs are remembered by changing the number in the line if [ $URLCount == 20 ] function AddRecentURL { # get directory script started from # 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 while read Line; do # Count lines in the file (( URLCount +=1 )) done < "$DirectoryName/RecentURLs.txt" # create temporary file to write new lines to touch "/tmp/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 clear else # add line to temp.txt echo "$Line" >> "/tmp/temp.txt" fi done < "$DirectoryName/RecentURLs.txt" else # write entire file to temp.txt while read Line; do echo "$Line" >> "/tmp/temp.txt" done < "$DirectoryName/RecentURLs.txt" fi # write most recent url to temp.txt echo "$1" >>"/tmp/temp.txt" # over write RecentURLs.txt with new list of recent URLs cat /tmp/temp.txt >"$DirectoryName/RecentURLs.txt" # remove temporary file rm -f "/tmp/temp.txt" } # Prompt user to select a log file, then show that log fle to them. function SelectLogFile { # Generate default log file name to open # get today's date for the daily log name. today=$(date +%d%m%Y) # Prompt user to choose a log file to open. FileName=`Xdialog --auto-placement --stdout --title "Web Site 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 Site Monitor - Log File Viewer - $LogName" --textbox "$FileName" 30 70 & } # Load today's log file into a tailbox to view the last entries. 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 Site Monitor - Current Log Entries - $today.log" --tailbox "$DirectoryName/logs/$today.log" 30 70 & } # Stop monitoring of one URL passed in as the second argument. function StopURL { # generate time stamp for daily log entry Time=$(date +%H:%M:%S) echo "$Time Stopping monitoring of - $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 "$2.html" rm -f "monitor$2.log" rm -f "messagedown$2.txt"; } function StopAllURLs { # loop through URLsMonitored.txt, and stop all running PollWebSite 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 < "/tmp/URLsMonitored.txt" # Remove old URLsMonitored.txt file since we are now monitoring nothing rm -f "/tmp/URLsMonitored.txt" # and initialize it to an empty file to prevent problems with StopMonitoringURL finding no file to read touch "/tmp/URLsMonitored.txt" # Notify the user that we have have stopped monitoring all URLs. Xdialog --auto-placement --title "Web Site Monitor - Stopped Monitoring" --msgbox "All URL monitoring has been stopped." 0 0 & } # This function loads the saved list of URLs and begins monitoring them all. function LoadSavedURLs { while read Line; do AddRecentURL $Line # generate time stamp for daily log entry Time=$(date +%H:%M:%S) echo "$Time Began monitoring $Line at $Interval second intervals." >>"logs/$Today.log" echo " " >>"logs/$Today.log" # monitor the URL on this line of the file. Execute in the background. MonitorWebSite.sh $Line $Interval & done < SavedURLList.txt # Notify user that all URLs have been loaded, and are now being monitored. Xdialog --auto-placement --title "Web Site Monitor - URLs 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 all urls in URLsMonitored.txt to SavedURLList.txt without the PID from the second half # of each line in the file. function SaveURLList { # Remove old SavedURLList.txt file so we can create a new one. rm SavedURLList.txt # initialize SavedURLList.txt file. touch SavedURLList.txt while read Line; do # Feed this line of URLsMonitored.txt to the parameter stripper to rid the line of the PID. BuildSavedList $Line done < "/tmp/URLsMonitored.txt" # notify user that file has been saved. Xdialog --auto-placement --title "Web Site Monitor - URL List Saved" --msgbox "URL list has been saved to SavedURLList.txt" 0 0 & } # 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 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" >> "/tmp/tmp.txt" fi } # Stop monitoring a specific url. function StopMonitoringURL { # test to see if /tmp/URLsMonitored.txt exists, and if it does not exit this function. if [ -e "/tmp/URLsMonitored.txt" ] then echo else return fi URLList="" # build list of urls currently being monitored from URLsMonitored.txt while read Line; do BuildList $Line done < "/tmp/URLsMonitored.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 Site 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 Site 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 # generate time stamp for daily log entry Time=$(date +%H:%M:%S) echo "$Time Stopping monitoring of - $URLtoMatch" >>"logs/$Today.log" echo " " >>"logs/$Today.log" # fetch PID of script monitoring that URL while read Line; do MatchURLforPID $Line done < "/tmp/URLsMonitored.txt" # Stop the process with the matched PID. kill "$PIDMatched" # write new shorter URLsMonitored.txt if [[ -e "/tmp/tmp.txt" ]] then cat "/tmp/tmp.txt" > "/tmp/URLsMonitored.txt" # Remove temporary files that instance of the script was using. rm -f "/tmp/tmp.txt" rm -f "/tmp/$PIDMatched.txt" fi fi } # Accept input from user on which url to monitor. The PollWebSite.sh script will add that url, and it's PID # to URLsMonitored.txt so those instances of the script can be shut down via their PIDs from this script. function BeginMonitoringURL { # Prompt user to enter a valid web url to monitor. WebURL=`Xdialog --auto-placement --stdout --title "Web Site 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 # generate time stamp for daily log entry Time=$(date +%H:%M:%S) echo "$Time Began monitoring $WebURL at $Interval second intervals." >>"logs/$Today.log" echo " " >>"logs/$Today.log" # begin monitoring the new url. MonitorWebSite.sh $WebURL $Interval &;; https://*) # Add URL to recent URLs List AddRecentURL $WebURL # generate time stamp for daily log entry Time=$(date +%H:%M:%S) echo "$Time Began monitoring $WebURL at $Interval second intervals." >>"logs/$Today.log" echo " " >>"logs/$Today.log" # begin monitoring the new url. MonitorWebSite.sh $WebURL $Interval &;; [0-9]*) Xdialog --auto-placement --title "Web Site Monitor - Malformed URL" --msgbox "Please enter a url of the form - http://www.somesite.com/folder/path/filename.ext?query" 0 0 & BeginMonitoringURL;; *) Xdialog --auto-placement --title "Web Site Monitor - Malformed URL" --msgbox "Please enter a url of the form - http://www.somesite.com/folder/path/filename.ext?query" 0 0 & BeginMonitoringURL;; esac } function MainMenu { MenuChoice=" " # while [ "$MenuChoice" != "Exit" ] do # Display the menu to the user, and record their choice in MenuChoice. MenuChoice=`Xdialog --auto-placement --stdout --no-tags --title "Web Site Monitor - Menu" --cancel-label "Exit" --menubox "Main Menu, please make your selection." 18 60 4 "AdjustInterval" "Adjust time interval between url checks." "AddURL" "Begin monitoring a URL." "StopURL" "Stop Monitoring a Single URL." "StopAll" "Stop Monitoring All URLs." "SaveURLs" "Save Current URL List to File" "LoadURLs" "Load, and Monitor Saved List of URLs" "RecentURLs" "Select Recently Monitored URL to Load" "CurrentLog" "View Current Log Entries" "SelectLog" "Select a Log File to View" "Background" "Exit GUI, and Continue Monitoring URLs" "Exit" "Exit Web Site Monitor, Discontinue Monitoring"` ReturnValue=$? # trap whether or not cancel was pressed case $ReturnValue in 1) # Cancel clicked # Stop monitoring all web urls. StopAllURLs # Remove temporary files used by scripts. rm -f "/tmp/go.txt" rm -f "/tmp/URLsMonitored.txt" exit;; 255) # X button clicked # Stop monitoring all web urls. StopAllURLs # Remove temporary files used by scripts. rm -f "/tmp/go.txt" rm -f "/tmp/URLsMonitored.txt" exit;; esac case $MenuChoice in "AddURL") BeginMonitoringURL &;; "StopURL") StopMonitoringURL &;; "StopAll") StopAllURLs;; "AdjustInterval") # prompt user for number of seconds to set the interval to with a spinner dialog. Interval=`Xdialog --auto-placement --stdout --title "Web Site Monitor - Set Interval" --spinbox "Set the spinner to the number of seconds you want for the timeout interval." 0 0 30 3600 300 "Seconds"`;; "SaveURLs") SaveURLList;; "LoadURLs") LoadSavedURLs;; "RecentURLs") LoadRecentURLs &;; "CurrentLog") ViewCurrentLog;; "SelectLog") SelectLogFile &;; "Background") exit;; esac done # Stop all remaining instances of the PollWebSite.sh script from running. StopAllURLs rm -f "/tmp/go.txt" # Remove temporary url, and PID recording file. rm -f "/tmp/URLsMonitored.txt" } # Main program starts here. # # Initialize variable for identifying the process id that goes with a certain URL being monitored. PIDMatched="" # Set interval between web site checks to it's default value of 300 seconds. Interval=300 Today=$(date +%d%m%Y) # get directory script started from DirectoryName="/home/$USERNAME/.WebSiteMonitor" mkdir --parents "$DirectoryName" cd $DirectoryName MainMenu exit
#!/usr/bin/env bash # # This is version 1.15 of MonitorWebSite.sh. # # This file checks a valid URL on a web server to see if it can download the file specified. # If it is successful in downloading the file, it simply sleeps a user specified interval, then checks again. # If it is not successful it will check to insure the Internet connection is good, then pop up a warning # that that web site is down, or that the Internet is down, whichever it is. # # It will continue to check the URL until it can once again successfully download the file, # then will pop up a dialog stating that the web site, or the Internet is back up again. # # USAGE: MonitorWebSite.sh http://www.somesite.com/filename.ext?query 300 # Where 300 is the sleep interval in seconds to wait between web site checks. # Replace http://www.somesite.com/filename.ext?query with the URL of an actual file # on your web site. [A small, or empty text file works quickest.] # ## Copyright: ## Copyright 2009 by C. Ray Parrish ## All Rights Reserved ## ## License: ## Released under the GNU General Public License (GPL) ## http://www.gnu.org/copyleft/gpl.html ## ## This program is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License ## as published by the Free Software Foundation; either version 3 ## of the License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## function SubtractTimes { # Assign some variables StartTime="$1" EndTime="$2" # Extract hours, minutes, and seconds from each time value # extract first two characters of StartTime StartHours=${StartTime:0:2} # get rid of leading zeros StartHours=${StartHours#0*} # extract minutes characters StartMinutes=${StartTime:3:2} # get rid of leading zeros StartMinutes=${StartMinutes#0*} # extract seconds from the end of StartTime StartSeconds=${StartTime:6:2} # get rid of leading zeros StartSeconds=${StartSeconds#0*} # trim first two characters from EndTime EndHours=${EndTime:0:2} # get rid of leading zeros EndHours=${EndHours#0*} # trim next two characters from front of Remainder EndMinutes=${EndTime:3:2} # get rid of leading zeros EndMinutes=${EndMinutes#0*} # extract seconds from the end of EndTime EndSeconds=${EndTime:6:2} # get rid of leading zeros EndSeconds=${EndSeconds#0*} # do the math to get the elapsed time if [[ $EndSeconds -lt $StartSeconds ]] then EndSeconds=$(( $EndSeconds + 60 )) EndMinutes=$(( $EndMinutes - 1 )) fi ElapsedSeconds=$(( $EndSeconds - $StartSeconds )) if [[ $EndMinutes -lt $StartMinutes ]] then EndMinutes=$(( $EndMinutes + 60 )) EndHours=$(( $EndHours - 1 )) fi # Take care of the case when the script starts before midnight, and ends after midnight. if [[ $EndHours -eq -24 ]] then EndHours=0 fi ElapsedMinutes=$(( $EndMinutes - $StartMinutes )) ElapsedHours=$(( $EndHours - $StartHours )) if [[ $ElapsedHours -gt 1 || $ElapsedHours -lt 1 ]] then HourLabel="Hours" else HourLabel="Hour" fi if [[ $ElapsedMinutes -gt 1 || $ElapsedMinutes -lt 1 ]] then MinuteLabel="Minutes" else MinuteLabel="Minute" fi if [[ $ElapsedSeconds -gt 1 || $ElapsedSeconds -lt 1 ]] then SecondsLabel="Seconds" else SecondsLabel="Second" fi echo "$ElapsedHours $HourLabel, $ElapsedMinutes $MinuteLabel, and $ElapsedSeconds $SecondsLabel" } # This function informs the user that the web site is down, and logs the fact. function WebSiteDown { URL="$1" LogFileName="$2" SiteDownTime="$3" if [[ $SiteDownTime == "" ]] then # Only tell user the first time the site goes down, not after every loop. SiteDownTime="$(date +%H:%M:%S)" xmessage "$SiteDownTime - $URL can not be downloaded, and the internet is connected, so the server must be down." echo "$SiteDownTime - $URL is no longer up and running." >> "$LogFileName" echo "$SiteDownTime" else # We warned the user last time or the time before that, so just echo the current SiteDownTime. echo "$SiteDownTime" fi } # This function checks to see if it can download the file specified in $URL, and logs it's success, or failure in the current log file. function CheckWebSite { # URL to check. URL="$1" # Name of the file for wget to save the downloaded URL to. FileName="$2" # Passed in ath and name of current log file is in the form - LogPath/$Today.log LogFile="$3" # Try to download URL. if wget --append-output="$LogFile" --connect-timeout=20 --output-document="/tmp/$FileName" "$URL" 2>/dev/null then # Remove the downloaded file so wget does not start creating copies of it with new file names each time through the loop. rm -f "/tmp/$FileName" # Return the fact that the site is up, and running. echo "Up" else # Return the fact that the site is likely down, but test the Internet connection first. echo "Down" fi } # This function checks /home/$USERNAME/.WebSiteMonitor/WebSiteMonitor.conf for the folder to write the log files into, and creates that folder if it does not exist. function InitializeLogFolder { # Load the path to the los folder from the configuration file. PathToLogs="`cat /home/$USERNAME/.config/WebSiteMonitor/WebSiteMonitor.conf`" if [[ "$PathToLogs" == "" ]] then PathToLogs="/home/$USERNAME/.WebSiteMonitor/logs" # make the directory, whether it exists or not, and make any parents required in it's path. mkdir --parents "$PathToLogs" echo "$PathToLogs" return fi # Take care of incorrectly entered path name from the configuration file. if [[ "${PathToLogs:0:1}" != "/" ]] then # Add a leading slash mark. PathToLogs="/$PathToLogs" fi # If the URL ends in a slash mark. if [[ "${PathToLogs:${#PathToLogs}:1}" == "/" ]] then # Trim off ending slash. PathToLogs="$[PathToLogs:0:$(( ${#PathToLogs} - 1 ))]" fi if [[ -ne "$PathToLogs" ]] then # make the directory, whether it exists or not, and make any parents required in it's path. mkdir --parents "$PathToLogs" fi # Return the path name for the logs folder to calling assignment. echo "$PathToLogs" } function NetBackUp { LogFileName="$1" NetDownTime="$2" NetUpTime="$3" TimeDifference="`SubtractTimes $NetDownTime $NetUpTime`" # Add an entry about the site being back up to the log file. echo "$NetUpTime - The Internet is back up after being down $TimeDifference." >>"$LogFileName" # Notify user that site is back up and running, and continue running the rest of the script immediately. xmessage "$NetUpTime - The Internet is back up after being down $TimeDifference." & # Reset the value of NetDownTime to a blank. echo "" } function SiteBackUp { URL="$1" LogFileName="$2" SiteDownTime="$3" SiteUpTime="$4" TimeDifference="`SubtractTimes $SiteDownTime $SiteUpTime`" # Add an entry about the site being back up to the log file. echo "$SiteUpTime - $URL is back up after being down $TimeDifference." >>"$LogFileName" # Reset the value of SiteDownTime to a blank. echo "" # Notify user that site is back up and running, and continue running the rest of the script immediately. xmessage "$SiteUpTime - $URL is back up after being down $TimeDifference." & } function InternetConnectionDown { LogFileName="$1" NetDownTime="$2" # Notify user if we haven't already if [[ "$NetDownTime" == "" ]] then echo "Internet connection has been broken." >> "$LogFileName" xmessage "The Internet connection has been broken. Please check your configuration, connections, and modem to be sure they are operating correctly." & NetDownTime="$(date +%H:%M:%S)" echo "$NetDownTime" else echo "$NetDownTime" fi } function InternetConnected { LogFileName="$1" FileName="$2" # Check to see if we can download robots.txt from a variety of servers. if wget --append-output="$LogFileName" --connect-timeout=20 --output-document="/tmp/$FileName" "http://www.microsoft.com/robots.txt" 2>/dev/null then # Output something to make the function return true. echo "Connected" rm -f "/tmp/$FileName" # We are done, so return from function. return fi # Repeat for the next three servers. if wget --append-output="$LogFileName" --connect-timeout=20 --output-document="/tmp/$FileName" "http://www.ebay.com/robots.txt" 2>/dev/null then echo "Connected" rm -f "/tmp/$FileName" return fi if wget --append-output="$LogFileName" --connect-timeout=20 --output-document="/tmp/$FileName" "http://www.paypal.com/robots.txt" 2>/dev/null then echo "Connected" rm -f "/tmp/$FileName" return fi if wget --append-output="$LogFileName" --connect-timeout=20 --output-document="/tmp/$FileName" "http://www.geeks.com/robots.txt" 2>/dev/null then echo "Connected" rm -f "/tmp/$FileName" return fi } # Main program starts here. # # Test passed in URL parameter for validity. case "$1" in http://*) # pass in the URL from the command line. URL=$1;; https://*) # pass in the URL from the command line. URL=$1;; *) echo -e "USAGE: MonitorWebSite.sh http://www.somesite.com/filename.ext 300 \n Where 300 is the interval in seconds." exit;; esac # Pass in the sleep interval in seconds, or set to 300 seconds if it is not passed in. if [[ "$2" == "" ]] then Interval=300 else Interval=$2 fi # Set up the logs directory if it does not already exist, and get path to it from WebSiteMonitor.conf. LogPath="`InitializeLogFolder`" # Add this script run's PID to URLsMonitored.txt for GUI wrapper script. touch "/tmp/URLsMonitored.txt" echo $URL $$ >> /tmp/URLsMonitored.txt # generate a file name for wget to save to from the PID of this script as it is assigned when it runs. FileName="$$.html" SiteDownTime="" SiteUpTime="" NetDownTime="" NetUpTime="" # Create loop control file. touch "/tmp/go.txt" while [ -e /tmp/go.txt ]; do # create daily log file name so we are always logging to a file with the current date in it's name. Today="$(date +%d%m%Y)" touch "$LogPath/$Today.log" # Check to see if the web site is up or down. UporDown="`CheckWebSite "$URL" "$FileName" "$LogPath/$Today.log"`" # React to status of web site check. case "$UporDown" in "Up") if [[ "$SiteDownTime" != "" ]] then # Calculate how long site was down, and write to the log file. SiteUpTime="$(date +%H:%M:%S)" # Notify user site is back up, and write fact to daily log file. SiteDownTime="`SiteBackUp "$URL" "$LogPath/$Today.log" "$SiteDownTime" "$SiteUpTime"`" fi if [[ "$NetDownTime" != "" ]] then # Get the time the Internet came back up. NetUpTime="$(date +%H:%M:%S)" # Notify user, and write to daily log file. NetDownTime="`NetBackUp "$LogPath/$Today.log" "$NetDownTime" "$NetUpTime"`" fi;; "Down") # If this is the first time it was detected to be down. if [[ "$SiteDownTime" == "" ]] then # If the Internet connection is good. if [[ `InternetConnected "$LogPath/$Today.log" "$FileName"` ]] then # Notify user, and write fact to daily log file. SiteDownTime="`WebSiteDown "$URL" "$LogPath/$Today.log" "$SiteDownTime"`" else # The Internet is down, notify user, and write to daily log file. NetDownTime="`InternetConnectionDown "$LogPath/$Today.log" "$NetDownTime"`" fi else # User already knows the site is down, so do not tell them again, but log fact to the daily log file. SiteDownTime="`WebSiteDown "$URL" "$LogPath/$Today.log" "$SiteDownTime"`" fi;; esac # Wait $Interval seconds before starting the next loop. sleep $Interval done exit
Using the GUI version of Web Site Monitor is all menu driven. Here is what the main menu looks like.
When you first start Web Site Monitor's GUI, it will not be monitoring any URLs of course. You should first specify the sleep interval you would like between web site checks, unless you want to accept the default of 300 seconds. To adjust the sleep interval of all subsequently monitored URLs select the first menu entry, "Adjust time interval between URL checks".
You will then get the following dialog which allows selecting an interval value of between 30, and 3600 seconds. You probably do not want to change the code to allow a smaller interval value than 30 seconds, as wget has a 20 second connection timeout by itself so trying to check once a second probably would not work well. 3600 seconds is one hour. If you need to specify longer sleep intervals than one hour, you will need to change the 3600 value in the Main Menu function within the case statement at AdjustInterval in WebSiteMonitor.sh
As with all dialogs in Web Site Monitor, clicking the Cancel button, or the title bar X button causes Web Site Monitor to return to the Main Menu after taking no actions.
The next menu entry "Begin Monitoring a URL" allows telling Web Site Monitor what web URLs you would like it to monitor. Web Site Monitor will monitor any valid web URL. These URLs should be in the following form -
http://www.somesite.com/folder/path/somefile.ext?query
Note that you may also use an HTTPS protocol on the front of the URL. When you select the second menu entry, you will get the following dialog.
You will need to use CTRL-V, or the clicking of your mouse scroll wheel to paste into the URL entry dialog, as Web Site Monitor does not support context menus. As the dialog says, you may type or paste in a new URL for Web Site Monitor to keep tabs on, then click OK.
The third menu entry is "Stop Monitoring a Single URL". This menu entry leads to a dialog with a drop down list of URLs to select from, and clicking OK on that dialog will make Web Site Monitor stop monitoring the currently selected URL in the drop down list.
The fourth menu entry is "Stop Monitoring All URLs", and produces no user prompts. This menu entry will cause all instances of MonitorWebSite.sh to immediately exit, and cleans up their temporary files. You will get a confirmation dialog that all URLs have stopped being monitored.
The fifth menu entry 'Save Current URL List to File" will save a list of all URLs currently being monitored to a text file in the Web Site Monitor working directory. This menu entry produces only a small dialog confirming that the current URL list has been saved to file.
The sixth menu entry "Load, and Monitor Saved List of URLs", will cause Web Site Monitor to load any previously saved list of URLs, and begin monitoring them. You will get only a small confirmation dialog from it.
The seventh menu entry "Select Recently Monitored URL to Load" will pop up a drop down list of the last 20 URLs you have told Web Site Monitor to monitor with the "Begin Monitoring URL" menu entry. If you would like to change the number of recent URLs that get saved change the number on the following line of the AddRecentURL function.
if [ $URLCount == 20 ]
Select one of the recent URLs from the drop down list, and click OK to start monitoring it again.
The eight menu entry "View Current Log Entries" will load the current log file into a tailbox which will continue to update whenever new entries hit the log file. This tailbox may be left running while using other features of Web Site Monitor as it executes in the background.
Each instance of MonitorWebSite.sh that is currently running will make log entries to a file named for today's date in the default /home/$USERNAME/.WebSiteMonitor/logs/ folder. These log files change names at midnight, and record successful, and unsuccessful attempts to download URLs being monitored. They also have entries about when a URL started, and stopped being monitored, when a web site goes down, and when a web site comes back up with the elapsed time of the outage.
You may change the folder path where Web Site Monitor stores it's log files by changing the value of the absolute path given in /home/$USERNAME/.config/WebSiteMonitor/WebSiteMonitor.conf to the path where you would like to keep the log files generated by MonitorWebSite.sh.
The ninth menu entry "Select a Log File to View" will present you with a file selection dialog with which to specify the log file you wish to look at. The file selection dialog opens in the current /logs folder for Web Site Monitor.
Select any log file to view, and click OK, and the log file will be loaded into a text box for viewing. You may select portions of the file for copying with your mouse, but will need to use CTRL-C to copy your selections, as Xdialog does not support context menus.
This menu entry can alternatively be used to load any text file into the viewer if you so wish. It is mainly intended for viewing Web Site Monitor's log files, but can be used to shortcut viewing any other file when you are in Web Site Monitor.
Here is a sample text box with a log file loaded. Note that the log entries are generated by wget as it attempts to download URLs to see if it can connect to your web sites.
You can see that it logs the time of the attempt, whether or not it was successful, and also gives you the effective transfer rate for the download if it was successful.
You may also note that the ip addresses of the web sites you are monitoring are resolved, and available to you in the log files. Wget also logs the size in bytes of the file that it downloaded as shown by the "Length" log file entry.
The tenth menu entry "Exit GUI, and Continue Monitoring URLs" does just that. You do not need Web Site Monitor's GUI running to continue monitoring the URLs you have specified with it. When you select this menu entry all instances of MonitorWebSite.sh that are running will continue to run.
Web Site Monitor keeps a text file in the /tmp/ directory of the URLs being monitored, and the corresponding PIDs of the script instances monitoring each one. Anytime you decide to restart Web Site Monitor's GUI, it will know what URLs are currently being monitored just as if it had never been stopped. You can even start instances of MonitorWebSite.sh from the command line, and the GUI will know about them.
The last menu entry "Exit Web Site Monitor, Discontinue Monitoring" will exit Web Site Monitor after stopping all URL monitoring.
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.