0

我已经为连接数据库创建了 shell 脚本。

#------------------------------------------------------------------------------------------
# Declaring a variable used in this program
#------------------------------------------------------------------------------------------
Databasename="XYZ"
#------------------------------------------------------------------------------------------
# ************************** MAIN PROGRAM STARTS ******************************************
#------------------------------------------------------------------------------------------

cd $SCRIPT_PATH

db2 connect to $Databasename

touch $UserId $RoleName $MCD_Prod

echo "UserId" > $UserId

echo "RoleName" > $RoleName

db2 -x "Select A.USER_ID from USER A ,ROLE_TYPE R, USER_ROLE U where A.USER_ID=U.USER_ID AND U.ROLE_ID=R.ROLE_ID" >> $UserId

db2 -x "Select R.ROLE_NM from USER A ,ROLE_TYPE R, USER_ROLE U where A.USER_ID=U.USER_ID AND U.ROLE_ID=R.ROLE_ID order by A.USER_ID" >> $RoleName
-------------------------------------------------------------------------------

当我在数据库中选择 * 未找到连接时,我已经进行了数据库验证。

但是,如果数据库名称从 "XYZ" 到 "XYZ1" 不正确,则数据库无法连接,但程序仅在此处终止..

我需要进行验证..请帮忙

4

1 回答 1

1

试试下面的代码...

if ! db2 -x "Select A.USER_ID from USER A ,ROLE_TYPE R, USER_ROLE U where A.USER_ID=U.USER_ID AND U.ROLE_ID=R.ROLE_ID" >> $UserId
then
  echo "there was an error, maybe the connection failed
fi
于 2013-08-27T06:28:30.840 回答