#!/bin/sh
#
# David Johnson (c)2000
#
# clean_hist.sh 
# Version 1.04
#
# Modification History
# V1.0   02/20/00 -first version
# V1.01  02/21/00 -Duc Do, cleaned up if statements and nawk command
# V1.02  02/22/00 -Winston Jenks fixed awk/nawk version issues
# V1.03  03/01/00 -KSF, refined the search for objects, improved awk
# V1.04  03/21/00 -Jim Kahlden, changed while loop to append to file
#
# Part of The Cassandra Project (http://thecassandraproject.org/)
#
# This script extracts the C:B.P points from the default Informix
# historian and checks to see if the point exists in the DCS. If 
# not the C:B.P is added to a list of bad points for extraction later.

if [ "`uname`" = "Windows_NT" ]
then
    echo "$0: only runs under Solaris. Sorry, better luck next time."
    exit
fi


# WDJ+ Check to see what version of AWK exists
NAWK="awk"
test -f /bin/nawk && NAWK="nawk"
# WDJ-


# Check for home location 
if  [ -n "$CASSANDRA_HOME" ]
then
#   it has been redefined at this site
    HOME=$CASSANDRA_HOME
else
#   it is not defined, try the default directory
    HOME="/opt/cassandra"
fi
#
if [ ! -d $HOME ]
then 
    echo "$0: Could not find directory $HOME. Program terminated."
    exit
fi
#
if [ ! -d $HOME/tmp ]
then
    mkdir $HOME/tmp
fi


# Now for the meat of it
cd /opt/fox/hstorian/bin
./cfgpts -v > $HOME/tmp/hist_pts1_$$.tmp


# That gives us the verbose listing of the points.


cd $HOME/tmp
# WDJ+ modify awk to use $NAWK variable and give it a chance to work on AW70
# I did not actually test this!!  But I did test the concept of using the 
# -F option to awk on the AW70 to pass a regular expression instead of a 
# single character.
# $NAWK -F[=,\,] '{ print $2 }' hist_pts1_$$.tmp | grep ":" > hist_pts2_$$.tmp
# WDJ-


# KSF+ further modify statement by running grep first on different pattern to
# retain OM variables as well as C:B.P points for validation.  Also shortened
# -F[=,\,] to -F[=,].
grep "^ID=" hist_pts1_$$.tmp | $NAWK -F[=,] '{ print $2 }' > hist_pts2_$$.tmp
# -KSF

# JHK+ change redirect output command (>) to append to file command (>>)
while read file
do
    /opt/fox/bin/tools/omget $file | grep does >> hist_miss_$$.tmp
    sleep 1
done < hist_pts2_$$.tmp
# JHK-


rm $HOME/tmp/hist_pts[12]_$$.tmp 2> /dev/null

# the end
