How to stop sqlplus command in unix shell script when any sql fails

0 votes

I am new to shell script . i am writing a code for DBA automation in which i have master.sql file have declarations of n number of sqls . and these sqls are placed inside particular folder . i have a script which is calling this master.sql and executing those sqls at once indirectly and saving in the log file

sqlplus command is saving the output of all the sqls declared inside master.sql at once wwhat i want is it must stop the execution when the first sql fails and return the error witht the specific sql which failed or ask to rollback and asking do you want to continue or not ? tried using sqlplus whenever,, sqlerror ,$? nothing worked

sqlplus  ${USER}/${PASS}@$SID  @master.sql > /home/deploy/vidya/properties/result/result.log

Now what i am trying to do is .... i want to stop the execution of sqls when any of the sql fails from the starting and prompts on the command line with the error and specify which sql fails

Jul 16, 2018 in Other DevOps Questions by Kalgi
• 2,680 points
2,980 views

1 answer to this question.

0 votes
One idea would be to launch the sql's in sequence and check them afterwards for errors: e.g.

sqlplus  ${USER}/${PASS}@$SID  @dba_demo.sql > /home/deploy/vidya/properties/result/result_dba_demoSQL.log

checker = $(grep "ERROR" result_dba_demoSQL.log)

if [ test -z $checker ]

   then echo "dba_demo_SQL successfull run"

   else

       echo "dba_demo_SQL failed"

       exit 0

fi

The exit 0 part, exits the whole script when grep find an error in the log file.
answered Jul 16, 2018 by Kalgi
• 52,310 points

Related Questions In Other DevOps Questions

0 votes
0 answers

How to use version name in Bamboo script

Hi All, We have 3 tasks in our ...READ MORE

Apr 8, 2020 in Other DevOps Questions by Abhishek
• 280 points
97 views
0 votes
1 answer

How to get issues count based on rules in a sonar project?

There are API docs in the footer ...READ MORE

answered May 4, 2018 in Other DevOps Questions by DareDev
• 6,890 points
1,330 views
+1 vote
2 answers

When do we use Chef or Azure SDK to create VM and deploy in automation

The solution to the automated deployment in ...READ MORE

answered Aug 21, 2018 in Other DevOps Questions by Priyaj
• 58,100 points
316 views
0 votes
1 answer

Command not working in .bat script but works in CLI

powershell /? If you run the above command ...READ MORE

answered Jul 19, 2018 in Other DevOps Questions by ajs3033
• 7,280 points
308 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 26, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
967 views
+2 votes
1 answer
0 votes
1 answer
0 votes
1 answer

how do i make apache2 site point outside the folder in ubuntu?

in apche2 configuration file u have to ...READ MORE

answered Jul 6, 2018 in Other DevOps Questions by Kalgi
• 52,310 points
100 views