#!/bin/sh
#
# Filename: hist_maint.sh
#
# Author:  Kevin FitzGerrell
# Comments to:  kfitz@gci.net or fitzgerrell@yahoo.com
# Most recent copy at www.geocities.com/fitzgerrell/dcs_stuff.html
#
# Usage:  Change the directories for GRAPHICS and OUTPUT to directories
# appropriate for your system.  GRAPHICS should be the directory that 
# contains your display files with user configured trends, or a parent 
# to the subdirectories that contain those files.  Run without parameters.
# Run may be substantial.  CPU load may be high while running the "find" 
# command step.
#
# Description:  This script will list to the file hist_bad.tmp
# 1 -- invalid points.
# 2 -- invalid points that are also in reduction groups.
# 3 -- reduction group points that are not configured in the historian.
# 4 -- valid points in the historian that are not used in user configured
#      trends or in reduction groups.
# Also generated will be files with some reference information.
#
# Created files:  
# hist_bad.tmp -- main report.
# reduct_points.tmp -- sorted list of points in reduction groups.
# trends.tmp -- list of display files with user configured trends.
# hist_points.tmp -- list of points in the historian.
# trends_points.tmp -- list of display files with user configured trends and 
#      their associated points.
# Intermediate files temp.1 - temp.5 are created and removed.
# dmpcfg.log will be created in the directory that this script is run from.
# 

# set directory that contains trend graphics (be as specific as possible)
GRAPHICS="/usr/sc"
# set directory that will contain output files
OUTPUT="/usr/scripts"
# Get base info for trended points (this can take a long time and lots of cpu capacity):
find $GRAPHICS -exec /usr/fox/wp/bin/tools/d_edit50 -l {} > $OUTPUT/temp.1 \;

# for list of graphics (filenames) that trend points and their associated points:
egrep '(^ */|^4[01][0-9])' $OUTPUT/temp.1 | sed 's$^ */$%/$g' | awk '{print $NF}' | nawk -F"\n" -v RS="%" '{ if ( NF > 2) print $0 }' > $OUTPUT/trends_points.tmp

# for list of graphics (filenames) that trend points:
egrep '(^ */|^4[01][0-9])' $OUTPUT/temp.1 | sed 's$^ */$%/$g' | awk '{print $NF}' | nawk -F"\n" -v RS="%" '{ if ( NF > 2) print $1 }' > $OUTPUT/trends.tmp

# for sorted list of points referenced by trends:
grep "^4[01][0-9]" $OUTPUT/temp.1 | awk '{ print $NF }' | sort -u > $OUTPUT/temp.2

# for sorted list of redution group points
/opt/fox/hstorian/bin/dmpcfg m | egrep '(Point |Input)' | awk '{print $2}' | sort -u > $OUTPUT/reduct_points.tmp

# for list of points in historian:
cd /opt/fox/hstorian/bin
cfgpts -v > $OUTPUT/temp.3
cd $OUTPUT
grep "^ID=" $OUTPUT/temp.3 | nawk -F"[=,]" '{ print $2 }' > $OUTPUT/hist_points.tmp
# to get list of invalid points in above:
while read file
do
  /opt/fox/bin/tools/omget $file | grep "does" > $OUTPUT/temp.4
  sleep 1
done < $OUTPUT/hist_points.tmp

# Build main report file:
echo "Invalid historian points:" > $OUTPUT/hist_bad.tmp
cat $OUTPUT/temp.4 >> $OUTPUT/hist_bad.tmp

# compare files, send output to main report file:
echo "\n\nInvalid points that exist in reduction groups as well as in the historian:" >> $OUTPUT/hist_bad.tmp
comm -23 $OUTPUT/temp.4 $OUTPUT/reduct_points.tmp >> $OUTPUT/hist_bad.tmp

echo "\n\nPoints in reduction groups but not in historian:" >> $OUTPUT/hist_bad.tmp
comm -13 $OUTPUT/hist_points.tmp $OUTPUT/reduct_points.tmp >> $OUTPUT/hist_bad.tmp

echo "\n\nPoints in historian that are not trended or reduced:" >> $OUTPUT/hist_bad.tmp
comm -23 $OUTPUT/hist_points.tmp $OUTPUT/reduct_points.tmp > $OUTPUT/temp.5
comm -23 $OUTPUT/temp.5 $OUTPUT/temp.2 >> $OUTPUT/hist_bad.tmp

# remove temporary files, comment out remove on files with potential for documentation.
rm temp.1
rm temp.2
rm temp.3
rm temp.4
rm temp.5
# rm trends.tmp
# rm trends_points.tmp
# rm hist_points.tmp
# rm reduct_points.tmp

    Source: geocities.com/fitzgerrell/dcs_stuff

               ( geocities.com/fitzgerrell)