0

I have created shell script for connection database.

#------------------------------------------------------------------------------------------
# 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
-------------------------------------------------------------------------------

i have made database validation when i select * in database an connection not found.

But if the database name is incorrrect from "XYZ" to "XYZ1" , database could not connect but program terminate here only..

I need to put validation ..Please help

1
  • Is their is any way in shell script where i can check ..is database is connected succufully or not and determinate program here only if not connected Commented Aug 27, 2013 at 6:18

1 Answer 1

1

Try it with the following code ...

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.