Conditional Execution of a Script.

I have a unix shell script Test.sh

more Test.sh

echo "Calling dbquery1.sh...."
./dbquery1.sh
echo "Calling dbquery2.sh...."
./dbquery2.sh

more dbquery1.sh

sqlplus  -s user1/password1@DB_SID @/tmp/storedprocedures/Hello.rcp

I run Test.sh

However, I do not want dbquery2.sh to be executed unless dbquery1.sh executes successfully[If there is any ORA Database error then also dbquery2.sh should not execute].

How can I achieve this ?

if dbquery1 returns a returncode, you can use it for the second script:

./dbquery1.sh
if [[ $? -eq 0 ]] ; then
echo "Calling dbquery2.sh...."
./dbquery2.sh
fi

or

./dbquery1.sh && ./dbquery2.sh

Hi, question is that sqlplus return an errorcode only if there are a connection issue, else in every case return 0.
A simple solution is to redirect the output to a tmp file and check the content:

echo "Calling dbquery1.sh...."
./dbquery1.sh > output.tmp
grep -q ORA- output.tmp
if [ $? -ne 0 ]
then 
echo "Calling dbquery2.sh...."
./dbquery2.sh
fi

sqlplus returns a meaningful return code when you tell it to do so.
You'll have to modify your sql-commandfile:

$ cat bad.sql
whenever sqlerror exit failure
select this_produces_an_error from dual;
exit 0
$
$ cat good.sql
whenever sqlerror exit failure
select dummy from dual;
exit 0
$
$ sqlplus -s / as sysdba @good.sql

D
-
X

$ echo $?
0
$
$ sqlplus -s / as sysdba @bad.sql
select this_produces_an_error from dual
       *
ERROR at line 1:
ORA-00904: "THIS_PRODUCES_AN_ERROR": invalid identifier


$ echo $?
1