收到错误数据库:0403-009 指定的数字对此命令无效。
代码::
#!/usr/bin/ksh
#set -x
WORKFILE="/tmp/oatest.out"
DDLFILE="/tmp/oatest.ddl"
TODOFILE="/tmp/oatest.todo"
LOCKFILE="/tmp/oatest.lck"
function cleanup
{
chmod 666 $WORKFILE
rm $WORKFILE
chmod 666 $TODOFILE
if [ -f $LOCKFILE ]; then
rm $LOCKFILE
fi
exit
}
if [[ $# -lt 1 || $# -gt 2 ]]; then
echo "Usage: $0 [INSTANCE] [DATABASE]"
cleanup
fi
if [[ $# -eq 1 ]]; then
typeset -l DBNAME=$1
typeset -u DBUPPER=$1
else
if [[ $# -eq 2 ]]; then
if [[ $2 == "all" ]]; then
typeset -l DBNAME="all"
else
typeset -l DBNAME=$2
fi
typeset -u DBUPPER=$2
fi
fi
typeset -u INSTUPPER=$1
typeset -l INSTLOWER=$1
typeset -i PROBLEMS=0
typeset -i DB2ACTIVE=0
typeset -i DBAVAIL=0
typeset -i NUMDB=0
typeset -i DBTEST=1
while [ -f $LOCKFILE ]; do
echo "oatest.lck lock file exists - waiting 15 seconds..."
sleep 15
done
touch $LOCKFILE
if [[ ! -f $WORKFILE ]]; then
touch $WORKFILE
fi
chmod 666 $WORKFILE
echo "" > $TODOFILE
chmod 754 $TODOFILE
if [[ DB2ACTIVE -eq 1 && DBAVAIL -eq 1 ]]; then
sudo -u $INSTLOWER sh -c ". /home/prods/db2/$INSTUPPER/.profile \
>/dev/null 2>&1;echo \"connect to $DBNAME;\" > $DDLFILE; echo \"select \
tbsp_auto_resize_enabled,tbsp_name from table(snap_get_tbsp('',-1)) as t \
where tbsp_type=0;\" >> $DDLFILE; db2 -tf $DDLFILE" > $WORKFILE
cat $WORKFILE|grep -v select|grep -v ${INSTUPPER}|grep -v ${DBUPPER} \
|egrep '0|1'|while read STATE TABSPACE; do
if [[ $STATE -eq 1 ]]; then
echo "OK - Autoresize enabled for $TABSPACE"
else
echo "ERROR - Autoresize disabled for $TABSPACE"
PROBLEMS=$PROBLEMS+1
fi
done
else
echo "ERROR - Cannot check tablespace autoresizing as db2 is inactive"
fi
++++++
调试模式 ::
+ [[ DB2ACTIVE -eq 1 ]]
+ [[ DBAVAIL -eq 1 ]]
+ sudo -u uom15c sh -c . /home/prods/db2/UOM15C/.profile >/dev/null 2>&1;echo "connect to mdmdb;" > /tmp/oatest.ddl; echo "select tbsp_auto_resize_enabled,tbsp_name from table(snap_get_tbsp('',-1)) as t where tbsp_type=0;" >> /tmp/oatest.ddl; db2 -tf /tmp/oatest.ddl
+ 1> /tmp/oatest.out
+ cat /tmp/oatest.out
+ read STATE TABSPACE
+ grep -v select
+ grep -v UOM15C
+ grep -v MDMDB
+ egrep 0|1
oatest[696]: Database: 0403-009 The specified number is not valid for this command.
答案1
尝试更换
if [[ DB2ACTIVE -eq 1 && DBAVAIL -eq 1 ]]; then
经过
if [[ ${DB2ACTIVE} -eq 1 && ${DBAVAIL} -eq 1 ]]; then
显然您没有提供正确的 DB2 ID。
答案2
进行如下更改后,它起作用了。
前:
if [[ $STATE -eq 1 ]]; then
后:
if [[ "$STATE" == 1 ]]; then