tente substituir
if [[ DB2ACTIVE -eq 1 && DBAVAIL -eq 1 ]]; then
por
if [[ ${DB2ACTIVE} -eq 1 && ${DBAVAIL} -eq 1 ]]; then
e, obviamente, você não forneceu o ID do DB2 adequado.
obtendo o erro como Banco de dados: 0403-009 O número especificado não é válido para este comando.
Código ::
#!/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
++++++
Modo de depuração ::
+ [[ 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.
tente substituir
if [[ DB2ACTIVE -eq 1 && DBAVAIL -eq 1 ]]; then
por
if [[ ${DB2ACTIVE} -eq 1 && ${DBAVAIL} -eq 1 ]]; then
e, obviamente, você não forneceu o ID do DB2 adequado.
Funcionou depois de fazer as alterações abaixo.
Antes:
if [[ $STATE -eq 1 ]]; then
Depois:
if [[ "$STATE" == 1 ]]; then