Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

variable stays the same no matter condition

Status
Not open for further replies.

cougartrace

Technical User
Sep 9, 2003
29
US
I have this piece of code in my korn shell script:

#***********************
# Check TableSpace State
#***********************
if [ $state = '0x10000000' ]
then
nstate = 'BALANCE'
elif [ $state = '0x0000' ]
then
nstate = 'NORMAL'
else
nstate = 'ABNORMAL'
fi

No matter what the $state is, if the first go through the loop is 0x0000 then all the way through the loop it sets nstate as normal. I've done the checking and the state is being passed right. What am i missing?
 
through the loop
Which loop ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
this is just a piece of code in a loop where I grate the state of the tablespace among other pieces of info.

My problem is that, if the 1st tablespace state is = 0x0000 then it sets the nstate = NORMAL (which is fine), however on the next tablespace, no matter what state is equaled to, it still sets nstate = NORMAL.
 
Any chance you could post the entire loop code ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
this script probably not suitable for posting because of length, unfortunately.
 
integer daily
daily=`date +%j`
dateh=$(date)
datet=$(date +"Date: %D Time: %T")
curdate=$(date +%Y%b%d_%H:%M)

s_name=`uname -n`

integer total
typeset -i psize
psize=0
upsize=0
tpsize=0




pct='85' # Send error message when the tablespace exceeds percent
thresh='3221225472' # If tablespace has 3 gig or more do not page for space not matter percent

echo "Start of Execution"
echo `date`

if [[ -z $1 ]] ; then
echo "************************************************"
echo "Error: No parameter provided for the instance id"
echo "************************************************"
mail -s "dbSpace failed - instance parameter missing" $mail_id
exit
else
instance=$1
fi ; # end of usage check for the instance id

#export DB_HOME=/db2data/$instance/sqllib
export DB_HOME=/db2/$instance/sqllib
export PATH=$PATH:$DB_HOME
#
. $DB_HOME/db2profile

rpt_dir=/db2/$instance/sqllib/log
rpt_name=dbSpace.$s_name.$instance.out
rpt_out=$rpt_dir/$rpt_name

spc_rpt_name=dbSpace.$s_name.$instance.$curdate.rpt
spc_rpt=$rpt_dir/$spc_rpt_name
touch $spc_rpt

#err_rpt_name=dbSpace.$s_name.$instance.$curdate.err
#err_rpt=$rpt_dir/$err_rpt_name
#touch $err_rpt


if [[ -z $2 ]] ; then
echo "*************************************************************" >> $rpt_out
echo "Error: No parameter provided for the remove reports statement" >> $rpt_out
echo "*************************************************************" >> $rpt_out
mail -s "dbSpace failed - reporting parameter missing" $mail_id < $rpt_out
else
days_retained=$2
fi ; # end of usage check for the days_retained parameter

if [[ -z $3 ]] ; then
echo "******************************************" >> $rpt_out
echo "Error: No database parameter was supplied " >> $rpt_out
echo "******************************************" >> $rpt_out
mail -s "dbSpace failed - database parameter missing" $mail_id < $rpt_out
exit
else
typeset -i count=1
while [[ "$3" != "" ]] ; do
database=$3
DATABASE=$database

psize=0
psizeK=0
fspace=0


echo "*******************************" >> $rpt_out
echo " dbSpace on Database: $DATABASE" >> $rpt_out
echo "*******************************" >> $rpt_out

db2 connect to $DATABASE
rc=$?
if [ "$rc" != 0 ] ; then
echo "****************************************" >> $rpt_out
echo "rc = $rc" >> $rpt_out
echo "Unable to connect to database $DATABASE " >> $rpt_out
echo "****************************************" >> $rpt_out
mail -s "$dbSpace failed - Connection to $DATABASE failed" $mail_id < $rpt_out
else
echo "Connection to database $DATABASE was successful" >> $rpt_out

#****************************************************#
# Print Header
#****************************************************#

echo $dateh >> $spc_rpt
echo "Server: " $s_name " Database:" $DATABASE >> $spc_rpt
echo ' ' >> $spc_rpt
echo "Table Page Num Total Used Free Percent" >> $spc_rpt
echo " Id TableSpace Name Type Size State Cont Pages Pages Used" >> $spc_rpt
echo "_____ _______________ ____ ____ _____ ____ _____ _____ _____ _______" >> $spc_rpt

#****************************************************#
# Parce Tablespace Command
#****************************************************#

db2 list tablespaces show detail | while read line ; do
w1=$(echo "$line" | cut -d" " -f1)
echo $w1

# If line is null .. give it a value to avoid a failure
if [ -z "$w1" ] ; then
unset w1
w1='jnko'
fi

if [ $w1 = "Tablespace" ] ; then
tabid=$(echo "$line" | cut -d'=' -f2)
fi
if [ $w1 = "Name" ] ; then
name=$(echo "$line" | cut -d'=' -f2)
fi
if [ $w1 = "Type" ] ; then
type=$(echo "$line" | cut -d'=' -f2)
type1=$(echo "$type" | cut -c1-7)
if [ $type1 = "System" ] ; then
Ttype='SMS'
else
Ttype='DMS'
fi
fi

if [ $w1 = "State" ] ; then
state=$(echo "$line" | cut -d'=' -f2)
fi
#echo $name $state $nstate >> trace.lst
if [ $w1 = "Total" ] ; then
total=$(echo "$line" | cut -d'=' -f2)
fi
if [ $w1 = "Usable" ] ; then
usable=$(echo "$line" | cut -d"="-f2)
fi
if [ $w1 = "Used" ] ; then
used=$(echo "$line" | cut -d'=' -f2)
fi
if [ $w1 = "Free" ] ; then
free=$(echo "$line" | cut -d'=' -f2)
fi
if [ $w1 = "Page" ] ; then
page=$(echo "$line" | cut -d'=' -f2)
fi
if [ $w1 = "Extent" ] ; then
extent=$(echo "$line" | cut -d"=" -f2)
fi

#*******************************************************#
# "number" is the last line returned for each tablespace
# and is the number of extents allocated at this time.
#
# Calculate the total number of pages for a tablespace
#*******************************************************#

if [ $w1 = "Number" or "Minimum" ] ; then
container=$(echo "$line" | cut -d'=' -f2)
(( upsize =$upsize + ($page*$used) ))
(( tpsize =$tpsize + ($page*$total) ))
(( upsizeM=($upsize/1024/1024) ))
(( tpsizeM=($tpsize/1024/1024) ))
(( upsizeG=($upsize/1024/1024/1024) ))
(( tpsizeG=($tpsize/1024/1024/1024) ))

#**************
# SMS Reporting
#**************
if [ "$Ttype" = "SMS" ] ; then
echo "Ttype is SMS: $Ttype"

unset free ; free='-'
unset pcnt ; pcnt='-'
else
x=$(printf "%s\n" 'scale = 4; '$used'/'$total' * 100' | bc)
pcnt=${x%??} # truncate the last two zeroes
fi

#**************
# DMS Reporting
#**************
#if [ "$Ttype" = "DMS" ] ; then
# wnum=${pcnt%???} # Make percent into a whole number
# if [[ -z $wnum ]] ; then
# wnum=0
# fi
# ((fspace = ($page * $free) ))
# if [ $wnum -gt $pct -a $thresh -gt $fspace ] ; then
# echo " Database:" $DATABASE >> $err_rpt
# echo " " >> $err_rpt
# echo "Table Id: $tabid TableSpacename: $name Percent full: $pcnt" >> $err_rpt
# mail -s " - TSPACE NEEDS SPACE" $pager_id < $err_rpt
# fi
#fi

#***********************
# Check TableSpace State
#***********************
if [ $state = '0x10000000' ]
then
nstate = 'BALANCE'
elif [ $state = '0x0000' ]
then
nstate = 'NORMAL'
else
nstate = 'ABNORMAL'
fi
echo $name $state $nstate >> trace.lst
# echo " " >> $err_rpt
# echo "Table Id: $tabid TableSpname: $name Bad TableSpacee State: $state" >> $err_rpt
# mail -s " - TSPACE IN BAD STATE" $pager_id < $err_rpt
#fi

#*************
# Print report
#*************
printf "%3s %-18s %3s %6s %10s %4s %9s %9s %8s %10s\n" $tabid $name $Ttype $page $nstate $container $total $used $free $pcnt >> $spc_rpt
fi # if [ $w1 = Number ]
done

#*************************
# Print out databasae size
#*************************
echo ' ' >> $spc_rpt
echo ' Used Database size in Mbytes ' $upsizeM >> $spc_rpt
echo ' Used Database size in Gbytes ' $upsizeG >> $spc_rpt
echo " " >> $spc_rpt
echo ' Allocated Database size in Mbytes ' $tpsizeM >> $spc_rpt
echo ' Allocated Database size in Gbytes ' $tpsizeG >> $spc_rpt

fi

shift
done

fi

#***************************
# Remove appropriate reports
#***************************
find $rpt_dir -name "dbSpace.$s_name.$instance.d*" -mtime +$days_retained -type f -exec ls {} \;
find $rpt_dir -name "dbSpace.$s_name.$instance.d*" -mtime +$days_retained -type f -exec rm {} \;

echo "End of Execution" >> $rpt_out
echo `date` >> $rpt_out

if test -r $rpt_out ; then
rm $rpt_out
else
echo "$rpt_out not found"
fi ; # end of checki


mail -s "Space Reporting for $s_name $instance completed" $mail_id2 < $spc_rpt
#
#



 
At least the portion of code setting the state value ?
To debug your script, put this instruction just before the loop:
set -x

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Put your nstate assign code inside this conditional:
if [ $w1 = "State" ] ; then
state=$(echo "$line" | cut -d'=' -f2)
fi
And write your report after all the reading is done.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top