watergrinder
MIS
In continuation to thread822-811945, I have come up with this script in order to check if the counts are steadily increasing. It is working.
I also have the following questions
1) A txt file is being used for each table. i.e these txt files store 5 count(*) values. Ex: 10 20 30 40 50 etc .. and they reside
in the directory where scripts are. Can I use txt files like this? Ghodmode originally used txt files in his solution ...
2) How to create txt files from the script? Ex: I want to create table1.txt dynamically from the script. Idea is that
whenever a new table is added to dat, a new txt file will automatically be created in order to store the counts.
3) Please comment on the quality of script
Thanks a lot in advance!
I also have the following questions
1) A txt file is being used for each table. i.e these txt files store 5 count(*) values. Ex: 10 20 30 40 50 etc .. and they reside
in the directory where scripts are. Can I use txt files like this? Ghodmode originally used txt files in his solution ...
2) How to create txt files from the script? Ex: I want to create table1.txt dynamically from the script. Idea is that
whenever a new table is added to dat, a new txt file will automatically be created in order to store the counts.
3) Please comment on the quality of script
Thanks a lot in advance!
Code:
#!/usr/bin/sh
. sqlplus.sh
###################################
check_tab_status ()
{
set -A checkcounts $*
x=${#checkcounts[*]}
eval mailfile=\$$(($# -1))
eval tabname=\$$(($#))
if [ ${checkcounts[$x-3]} -ne 0 ]
then
i=0
j=0
while [ $i -lt $x-3 ]
do
if [ ${checkcounts[$i+1]} -gt ${checkcounts[$i]} ]
then
j=`expr $j + 1`
fi
i=`expr $i + 1`
done
fi # End if for NE check
if [ $j -eq $x-3 ]
then
echo "TABLE $tabname Steadily Increasing" >> $mailfile
fi
}
##################################
##################################
calc_tab_counts ()
{
# Temporary files.
COUNTFILE="/tmp/$2.txt" # tab count(*) data is stored here
SQLTEMP="/tmp/montabs.out"
set -A allcounts $(<$COUNTFILE) # Initialize array allcounts from countfile
# Count the number of elements in allcounts. If it is less than five then ..... ???
x=${#allcounts[*]}
if [ $x -lt 5 ]
then
set -A allcounts 0 0 0 0 0
fi
connect_oracle_sqlplus aaa bbb ccc $SQLTEMP "select count(*) from $2" # Connect to oracle.
# Find the current d/b count(*).
CURRENT_DB_COUNT=`cat $SQLTEMP | tr -d ' ' | sed /^$/d`
# Add the current d/b count, drop the oldest count.
i=0
x=${#allcounts[*]}
while [ $i -lt $x ]
do
allcounts[$i]=${allcounts[$i+1]}
i=`expr $i + 1`
done
allcounts[$x]=$CURRENT_DB_COUNT
# If current d/b count is zero, exit the script. No further processing is needed.
if [ $CURRENT_DB_COUNT -eq 55 ]
then
exit 0
fi
check_tab_status ${allcounts[*]} $1 $2 # Pass the count(*), mailfile and tab name
#rm $SQLTEMP # Remove tmp file
echo ${allcounts[*]} > $COUNTFILE # Update countfile
}
##################################
##################################
monitor_tab_counts ()
{
cat montabs.dat | awk '{ print $1 }' | while read TABLE
do
calc_tab_counts $1 "$TABLE" # Pass mailfile, table name as parameters
done
}
##################################