#!/bin/sh
#
#  get_cp
#
#  Usage:   get_cp
#
#  By: Angel Corbera, TSID1, Refinery Isla, Curacao, N.A.
#  Comments to:  corbera@rocketmail.com
#
#  Purpose:  Create a Control Blocks database from CP's data
#            for the entire system.
#  Database format:  
#            CP - CMPD - BLOCK - BLOCK_TYPE - DESCRIPTION
#  Note:  ECB blocks are NOT included.
#
#
cd /opt/ac
rm tmp1 tmp2 > /dev/null 2>&1
touch tmp1
CPS=`sort /etc/cplns`
TOOLS="/opt/fox/bin/tools"
echo "Retrieving data from All CP/GWs in the system ... \c"
$TOOLS/getpars -n -mCMPNM:%13s -mCP:%7s -mTYPE:%6s -mDESCRP:%32s >> tmp1
echo "Done!"
echo "Rearranging fields, deleting blank lines ... \c"
sed -e '/^BLOCK-NAME/d' tmp1 > tmp2
sed -e '/^Command/d' tmp2 > tmp1
sed -e '/^ .*/d' tmp1 > tmp2
sed -e '/^$/d' tmp2 > tmp1
awk '{printf "%6s %-12s %-12s %-7s %-0s %0s %0s %0s %0s %0s %0s\n",$3,$2,$1,$4,$5,$6,$7,$8,$9,$10,$11}' tmp1 > PLANT.cp
echo "Done!"
BLKS=`wc -l PLANT.cp | awk '{print $1}'`
echo "PLANT.cp ($BLKS blocks) is ready!"
#
echo "Building Statistics ...  \c"
rm PLANT.sum > /dev/null 2>&1
touch PLANT.sum
TOT=`wc -l PLANT.cp|awk '{print $1}'`
echo "Plant statistics for: `date`" >> PLANT.sum
echo "Total blocks = $TOT" >> PLANT.sum
echo "==============================================" >> PLANT.sum
echo "...  \c"
#
awk '{print $1}' PLANT.cp > tmp1
for x in $CPS
do
NUMBER=`grep $x tmp1 | wc -l` 
PCT=`expr 100 \* $NUMBER / $TOT`
echo "$x  blocks = $NUMBER \t( $PCT %)" >> PLANT.sum
done
echo "==============================================" >> PLANT.sum
echo "... \c"
#
awk '{print $4}' PLANT.cp > tmp1
sort -u tmp1 > tmp2
for x in `cat tmp2`
do
NUMBER=`grep $x tmp1 | wc -l` 
PCT=`expr 100 \* $NUMBER / $TOT`
echo "$x \tblocks = $NUMBER \t( $PCT %)" >> PLANT.sum
done
#
echo "Done. PLANT.sum (statistics) is ready!"
echo "\n Press SPACE for next page.  "q" to QUIT\n"
more PLANT.sum PLANT.cp
rm tmp1 tmp2
more PLANT.cp
1