#! /bin/sh
#------------------------------------------------------------------------
# This script simply monitors directory where the system test output
# is being written.
#------------------------------------------------------------------------
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# Configuration Variables
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
SCREEN_REFRESH_INTERVAL_SEC=120
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# Local Variables
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
comment_char=':'
found_errors="1"
system_testing_finished='1'
cnt='0'
while test $cnt -lt 75
do
  line="${line}${comment_char}"
  cnt="`expr $cnt + 1`"
done
#========================================================================
# Main
#========================================================================
while test $system_testing_finished -ne 0
do
  #----------------------------------------------------------------------
  # Provide a clean slate for the output
  #----------------------------------------------------------------------
  clear
  #----------------------------------------------------------------------
  # Get a listing of the files created so far.
  # Order these files in reverse order by last modified time (most
  #   recently modified appears at the bottom of the screen).
  #----------------------------------------------------------------------
  ls -lrt
  #----------------------------------------------------------------------
  # Look to see if any errors have been reported
  #----------------------------------------------------------------------
  case $found_erros in
  0)
     ;;
  *) grep -L FAILED *.log 2>&1 > /dev/null
     found_errors=$?
     ;;
  esac
  case "$found_errors" in
  0) echo $line
     echo "${comment_char} E R R O R   S U M M A R Y"
     echo $line
     grep FAILED *.log | (
       while read x;
	 do
	   echo $x
	 done
       )
     ;;
  esac
  #----------------------------------------------------------------------
  # Check on finished status
  #----------------------------------------------------------------------
  finished_text="`grep Finished: summary_report.txt`"
  case "$finished_text" in
  "") #------------------------------------------------------------------
      # Timestamp this information
      #------------------------------------------------------------------
      echo $line
      echo "${comment_char} T I M E S T A M P"
      echo $line
      date
      #------------------------------------------------------------------
      # Let the information sit for awhile
      #------------------------------------------------------------------
      sleep $SCREEN_REFRESH_INTERVAL_SEC
     ;;
  *) system_testing_finished="0"
     echo $line
     echo "${comment_char} S Y S T E M    T E S T I N G    C O M P L E T E D"
     echo $line
     echo $finished_text
     ;;
  esac
done
