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,620 points
824 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
• 42,510 points

Related Questions In Other DevOps Questions

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,810 points
453 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
• 56,940 points
152 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
41 views
0 votes
1 answer

Using conditional to execute a command in salt

You can use unless inside your state ...READ MORE

answered Jul 23, 2018 in Other DevOps Questions by DareDev
• 6,810 points
107 views
+13 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,380 points
217 views
0 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
• 42,510 points
42 views