Re: How to determine a db's dbpace?
Posted in 1994
> Anyone know how to determine a database's dbspace in a manner
> that can be done from a UNIX shell script? I need to create
> a shell script that creates a database in the same dbspace as
> a related database but cannot make any assumptions about which
> dbspace that might be.
>
> Thanks is advance!
>
> Roger Tomas
> tomasr@agcs.com
>
I am posting this shell script to the net because it's principal of operation
is based on information which was originally posted to this list several months
ago. All standard disclaimers apply, neither I nor the company which employs
me should be held responsible for any problems you may experience should you
use this code. Now that this has been said...
The following shell script works for me under both SCO UNIX and CLIX UNIX.
If you pass this script a database name and a table name, it will return
to you the dbspace which this table exists in. If you are un-able to modify
it to require only the database name as an argument you could allways pass
it systables as the table name.
Example
Entering: dbspace.sh -d SOME_DATABASE_NAME -t systables
Should return: systables:rootdbs
----- cut here ---- cut here ---- cut here ---- cut here ---- cut here ----
################################################################################
# Program: dbspace.sh #
# Author: Walter S. Tyszka #
# Date Created: 07/31/94 #
# -------------------------------------------------------------------------- #
# This program will return the dbspace in which TABLE is located. #
################################################################################
VERSION="01.00.00.00"
USAGE="$0 -d database -t {tablename | all} -f outfile"
if [ "$#" -eq 0 ]
then
echo "$USAGE"
exit 1
fi
while getopts vhf:d:t: c
do
case $c in
f) OUTFILE=$OPTARG;;
d) DATABASE=$OPTARG;;
t) TABLE=$OPTARG;;
v) echo $VERSION
exit 0;;
* | h) echo "$USAGE"
exit 1;;
esac
done
if [ -z "$DATABASE" -o -z "$TABLE" ]
then
echo "$USAGE"
exit 1
fi
if [ -n "$OUTFILE" ]
then
cp /dev/null $OUTFILE || exit 1
fi
typeset -i DBSPACENUM
cp /dev/null tblspace.tmp || exit 1
if [ "$TABLE" = "all" -o "$TABLE" = "ALL" ]
then
cp /dev/null tblname.tmp || exit 1
isql >tblname.tmp $DATABASE 2>/dev/null <<+
select tabname
from systables
where tabtype = "T" and (locklevel = "R" or locklevel = "P")
order by tabname;+
for TABLE in `cat tblname.tmp | grep -v tabname`
do
isql >tblspace.tmp $DATABASE 2>/dev/null <<+
select tabname,
hex(partnum)
from systables
where tabname = "$TABLE"+
DBSPACENUM=`grep $TABLE tblspace.tmp | cut -c22-23`
DBSPACENAM=`tbstat -d | awk '$2 ~ /^'$DBSPACENUM'/ && $7 ~ /^[a-z]/ {print $8}'`
if [ -f "$OUTFILE" ]
then
echo "$TABLE:$DBSPACENAM" | tee -a $OUTFILE
else
echo "$TABLE:$DBSPACENAM"
fi
cp /dev/null tblspace.tmp
done
rm tblname.tmp
else
isql >tblspace.tmp $DATABASE 2>/dev/null <<+
select tabname,
hex(partnum)
from systables
where tabname = "$TABLE"+
DBSPACENUM=`grep $TABLE tblspace.tmp | cut -c22-23`
DBSPACENAM=`tbstat -d | awk '$2 ~ /^'$DBSPACENUM'/ && $7 ~ /^[a-z]/ {print $8}'`
if [ -f "$OUTFILE" ]
then
echo "$TABLE:$DBSPACENAM" | tee -a $OUTFILE
else
echo "$TABLE:$DBSPACENAM"
fi
fi
rm tblspace.tmp
exit 0
################################################################################
----- cut here ---- cut here ---- cut here ---- cut here ---- cut here ----
--
--------------------------------------------------------------------------
Walter S. Tyszka | It's all just | wstyszka@ingr.com
Product Support Administrator | a matter of | 205-730-5723
Intergraph Corporation | perception. | Huntsville, Alabama
--------------------------------------------------------------------------