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
5,221 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,350 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 9, 2020 in Other DevOps Questions by Abhishek
• 280 points
834 views
0 votes
0 answers
0 votes
0 answers
+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 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,062 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,350 points
819 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP