sdo
6 years agoModerator
watch-vox script - a vox monitor
FYI - just a bit of fun... for anyone else who wants to keep an eye on Vox.
To run it :
1) save the script somewhere as : watch-vox.sh
2) start a Terminal or PuTTY or ssh session
3) cd to the folder where you saved the script
4) then run it using: ./watch-vox.sh
.
Here's the script :
#!/bin/bash #...for Solaris, change the above to: #!/usr/bin/bash #...but, on my test x86 Solaris 10.13 and Solaris 11.3 systems, I didn't need to. ############################################################################################################# # File: watch-vox.sh # Purpose: Script to watch VOX forum(s) for updates. # # Vers Date Who Description # ---- ---- --- ----------- # v0.01 12-Jan-2017 sdo Initial draft. # v0.02 12-Jan-2017 sdo Only log when something has changed. # v0.03 12-Jan-2017 sdo Log every 100 iterations. # v0.04 13-Jan-2017 sdo Append the diff to the log. Diff -y and suppress. # v0.05 13-Jan-2017 sdo Place all temporary working files in script path. # v0.06 14-Jan-2017 sdo Check status of curl web page fetch. # v0.07 15-Jan-2017 sdo Only move file if curl web page fetch is successful. # v0.08 21-Jan-2017 sdo Test status of initial search to handle successful page fetch which is empty. # v0.09 21-Jan-2017 sdo More capture of stderr to the log file. # v0.10 21-Jan-2017 sdo Store the data files in a sub-folder. # v0.11 21-Jan-2017 sdo Test size of page/file retrieved by curl. # v0.12 22-Jan-2017 sdo Also able to monitor the Article and Downloads by searching for match3. ############################################################################################################# SCRIPT_VERSION="v0.12" ############################################################################################################# # On a Mac, the following command could be used to extend the dwell time of popups... # defaults write com.apple.notificationcenterui bannerTime 5 ############################################################################################################# DEBUG=false MACOS=false LINUX=false SOLARIS=false if [ "$(uname -s)" = "Darwin" ] ; then MACOS=true ; fi if [ "$(uname -s)" = "Linux" ] ; then LINUX=true ; fi if [ "$(uname -s)" = "SunOS" ] ; then SOLARIS=true ; fi ############################################################################################################# ############################################################################################################# ### ...SCRIPT FUNCTIONS... function abort { log "script aborting..." if [ -z "$STS" ] ; then STS=-1; fi if [ $STS -eq 0 ] ; then STS=-1; fi exit $STS } function log { LOGDT=$(date "+%d/%m/%Y %H:%M:%S") echo "$LOGDT $1" echo "$LOGDT $1">>"$FILELOG" } ################################################################################# ################################################################################# ### ...SCRIPT JACKET... if [ "$MACOS" = "true" ] then pushd $(dirname "$0") >/dev/null SCRIPT_PATH=$(pwd -P) popd >/dev/null fi if [ "$LINUX" = "true" ] then SCRIPT_PATH=$(dirname "$0") SCRIPT_PATH=$(readlink -f "$SCRIPT_PATH") fi if [ "$SOLARIS" = "true" ] then pushd $(dirname "$0") >/dev/null SCRIPT_PATH=$(pwd -P) popd >/dev/null fi SCRIPT_DATA="$SCRIPT_PATH/DATA" SCRIPT_NAME=$(basename "$0") SCRIPT_NAME=${SCRIPT_NAME%%.*} FILEDIF="$SCRIPT_PATH/$SCRIPT_NAME.dif" FILELOG="$SCRIPT_PATH/$SCRIPT_NAME.log" FILETMP="$SCRIPT_PATH/$SCRIPT_NAME.tmp" FILETXT="$SCRIPT_PATH/$SCRIPT_NAME.txt" if [ -f "$FILEDIF" ] ; then rm "$FILEDIF" ; fi if [ -f "$FILELOG" ] ; then rm "$FILELOG" ; fi if [ -f "$FILETMP" ] ; then rm "$FILETMP" ; fi if [ -f "$FILETXT" ] ; then rm "$FILETXT" ; fi ((STEP=0)) ################################################################################# ################################################################################# ### ...START LOGGING... ((STEP++)) log "" log "" log "Step $STEP - show script details..." log "...script name: $SCRIPT_NAME" log "...script path: $SCRIPT_PATH" log "...script data: $SCRIPT_DATA" log "...script log: $FILELOG" log "...script version: $SCRIPT_VERSION" log "...done..." ################################################################################# ################################################################################# ### ...SCRIPT DETAILS... ((STEP++)) log "" log "Step $STEP - show server details..." log "...OS kernel: $(uname -r)" log ".. OS date: $(uname -v)" log "...OS platform: $(uname -m -p)" if [ "$RELEASE" != "" ] then log "...OS release: $(cat $RELEASE)" fi log "...hostname: $HOSTNAME" log "...process ID: $$" log "...num params: $#" log "...username: $USER" log "...current path: $PWD" log "...done..." ################################################################################# ################################################################################# ### ...INITIALISATION... ((STEP++)) log "" log "Step $STEP - initialisation..." if [ ! -d "$SCRIPT_DATA" ] ; then log "...creating data folder..." mkdir -pv "$SCRIPT_DATA" >>"$FILELOG" 2>&1 STS=$? if [ $STS != 0 ]; then log "...mkdir failed, status: $STS" abort fi log "...folder created ok..." fi log "...the URLs to monitor are:" URLS[1]="https://vox.veritas.com/t5/NetBackup/bd-p/netbackup" URLS[2]="https://vox.veritas.com/t5/NetBackup-Appliance/bd-p/netbackup-appliance" URLS[3]="https://vox.veritas.com/t5/OpsCenter/bd-p/opscenter" URLS[4]="https://vox.veritas.com/t5/Articles/tkb-p/Articles-Backup-and-Recovery" URLS[5]="https://vox.veritas.com/t5/Downloads/tkb-p/Downloads-Backup-and-Recovery" for (( CNT = 1 ; CNT <= ${#URLS[@]} ; CNT++ )) do URL=${URLS[$CNT]} log "...num: $CNT URL: $URL" touch "$SCRIPT_DATA/old$CNT.txt" touch "$SCRIPT_DATA/new$CNT.txt" done log "...done..." ################################################################################# ################################################################################# ### ...MAIN BODY... ((STEP++)) log "" log "Step $STEP - begin monitoring..." LOOP=0 for (( ; ; )) ; do ((LOOP++)) if (( $LOOP % 100 == 0 )) ; then log "...loop: $LOOP" ; fi for (( CNT = 1 ; CNT <= ${#URLS[@]} ; CNT++ )) do URL=${URLS[$CNT]} curl $URL -L --compressed -s >"$FILETXT" 2>>"$FILELOG" STS=$? if [ $STS != 0 ] ; then log "...curl failed, status: $STS" sleep 3 else SIZE=$(POSIXLY_CORRECT=1 du -k -- "$FILETXT" | awk '{print $1; exit}') if [ "$SIZE" -lt "100" ] ; then log "...ignoring $CNT, file size too small: $SIZE KB" sleep 3 else MATCH1="page-link lia-link-navigation lia-custom-event" MATCH2="lia-link-navigation lia-page-link lia-user-name-link" MATCH3="pge-link" egrep "$MATCH1|$MATCH2|$MATCH3" "$FILETXT" >"$FILETMP" 2>>"$FILELOG" STS=$? if [ $STS != 0 ]; then log "...egrep failed, status: $STS" sleep 3 else sed -e 's/^[[:space:]]*//' -i .bak "$FILETMP" sed -e "s/$MATCH1//" -i .bak "$FILETMP" sed -e "s/$MATCH2//" -i .bak "$FILETMP" sed -e "s/$MATCH3//" -i .bak "$FILETMP" sed -e 's/a class=""//' -i .bak "$FILETMP" sed -e 's/ id="link_[^"]*" / /' -i .bak "$FILETMP" sed -e 's/ target="_self" / /' -i .bak "$FILETMP" sed -e 's/ style="color:[^"]*" / /' -i .bak "$FILETMP" sed -e 's/ href="\/t5\/user\/[^"]*">/ /' -i .bak "$FILETMP" sed -e 's/\<span class="[^"]*">//' -i .bak "$FILETMP" sed -e 's/\<\/span>\<\/a>//' -i .bak "$FILETMP" sed -e 's/\href="//' -i .bak "$FILETMP" sed -e 's/">//' -i .bak "$FILETMP" sed -e 's/^\< //' -i .bak "$FILETMP" mv "$SCRIPT_DATA/new$CNT.txt" "$SCRIPT_DATA/old$CNT.txt" 2>>"$FILELOG" STS=$? if [ $STS != 0 ] ; then log "...rename failed, status: $STS" abort fi cat "$FILETMP" | tail -r | tail -n +6 | tail -r >"$SCRIPT_DATA/new$CNT.txt" STS=$? if [ $STS != 0 ] ; then log "...cat and tail failed, status: $STS" abort fi diff -y --suppress-common-lines "$SCRIPT_DATA/new$CNT.txt" "$SCRIPT_DATA/old$CNT.txt" >"$FILEDIF" 2>>"$FILELOG" STS=$? if [ $STS = 1 ] ; then echo -n -e "\a\a\a" log "...updated: $URL" cat "$FILEDIF" >>"$FILELOG" if [ "$MACOS" = "true" ] ; then osascript -e "display notification \"$URL\" with title \"updated\"" fi else if [ $STS != 0 ] ; then log "...diff failed, status: $STS" abort fi fi fi fi fi done sleep 300 done ################################################################################# ################################################################################# exit