Error handling with shell script
Hi,
I want to write a .sql file with lots of executable statements. These statements need to run on 100 of schemas per database.
I want to have error handling mechanism in this file in such a way that whenever I get any ORA- error or SP error, it should stop executing there.
Please help me.
Thanks.
872305 wrote:
Hi,
I want to write a .sql file with lots of executable statements. These statements need to run on 100 of schemas per database.
I want to have error handling mechanism in this file in such a way that whenever I get any ORA- error or SP error, it should stop executing there.
Please help me.
Thanks.
10:47:51 SQL> help whenever sqlerror
WHENEVER SQLERROR
Performs the specified action (exits SQL*Plus by default) if a
SQL command or PL/SQL block generates an error.
WHENEVER SQLERROR {EXIT [SUCCESS|FAILURE|WARNING|n|variable|:BindVariable]
[COMMIT|ROLLBACK] | CONTINUE [COMMIT|ROLLBACK|NONE]}
10:48:07 SQL>
Similar Messages
-
Oracle Error Handling in Shell Scripts
I need to manage 2 diferente class of errors :
Oracle Errors(produced in compilation time) and
Operating Syste Error(e.g. No Datbase conection ORA-1017,etc) my shell its KSH.
Please can you help me how can I manage then?
this my alternative but is not correct ;
#creating conexion with sql
exit | sqlplus -s $USERPV_DB/$PWDPV_DB @$VORDSQLPATH/ord.extractor_porven.sql $VFDESDE $VFHASTA > $VORDDATOS_PATH/ord.extractor_porven$VDATE.dat 2>> $VLOG
#Evaluating last sentence (sqlplus . . . . )
VERROR=$?
#Si VERROR=0 should stop process execution and alert with echo ".."Oracle error handling before compilation time
if [ $VERROR != 0 ]
then
echo "value of VERROR are:$VERROR"
echo "`date +"$V_FORMATDATE"` DATA EXTRACTION WAS NOT SUCESSFUL ERROR BEFORE COMPILATION TIME" >> $VLOG 2> /dev/null
" Here show VERROR
else #Oracle error handling in compilation time
echo "`date +"$V_FORMATDATE"` DATA EXTRACTION WAS NOT SUCESSFUL ERROR BEFORE COMPILATION TIME " >> $VLOG
" Here show VERROR
else if [ $VERROR = 0 ]
" DATA EXTRACTION WAS SUCESSFUL"
fi
Would apreciate your help its very urgent.
Best Regards
Antoniouser5647282 wrote:
I need to manage 2 diferente class of errors :
Oracle Errors(produced in compilation time) and
Operating Syste Error(e.g. No Datbase conection ORA-1017,etc) my shell its KSH.
Please can you help me how can I manage then?
this my alternative but is not correct ;
#creating conexion with sql
exit | sqlplus -s $USERPV_DB/$PWDPV_DB @$VORDSQLPATH/ord.extractor_porven.sql $VFDESDE $VFHASTA > $VORDDATOS_PATH/ord.extractor_porven$VDATE.dat 2>> $VLOG
Piping the output of 'exit' to sqlplus????????? what do you expect from this?
#Evaluating last sentence (sqlplus . . . . )
VERROR=$?any error returned by sqlplus as $? would be a fatal error of sqlplus itself, not any error returned by processing a sql statement. If your script ord.extractor_porven.sql were to generate, say, an ORA-00001, that is NOT an error in sqlplus and so does not return to the OS as an error of sqlplus.
#Si VERROR=0 should stop process execution and alert with echo ".."Oracle error handling before compilation time
if [ $VERROR != 0 ]
then
echo "value of VERROR are:$VERROR"
echo "`date +"$V_FORMATDATE"` DATA EXTRACTION WAS NOT SUCESSFUL ERROR BEFORE COMPILATION TIME" >> $VLOG 2> /dev/null
" Here show VERROR
else #Oracle error handling in compilation time
echo "`date +"$V_FORMATDATE"` DATA EXTRACTION WAS NOT SUCESSFUL ERROR BEFORE COMPILATION TIME " >> $VLOG
" Here show VERROR
else if [ $VERROR = 0 ]
" DATA EXTRACTION WAS SUCESSFUL"
fi
Would apreciate your help its very urgent.
there is no "urgent" here.
"Urgent" means one of two things -
1) people are dying, or
2) you have a customer-facing, revenue-producing production system that is down.
(And to get some perspective on the second case, keep the first in mind.)
For the first, you call whatever civil emergency service seems appropriate.
For the second, you open an SR with Oracle - which requires a paid-up support contract. For them to consider your problem "urgent", you will need to demonstrate that your problem falls under item #2. I seriously doubt your problem fits that criteria.
Best Regards
Antonio -
SQL in Connection with shell scripts
Hello everyone,
I have a conceptual question:
If people like to implement their SQL-Scripts attached on a shell script(Ruby, Perl, or even OS-Shell), what are actually the benefits doing this? Can someone please give me a szenario, which is very effectively if we do it with combination with shell-script.
My second question: does oracle sql developer support this shell combination?
Thank you..Wrapping sql script in a shell script provides flexibility. Shell can provide better parameter validation than SQL, better output handling, and better error trapping. Personally I would have the sql script separately for purist modularisation reasons, but you can merge the two.
e.g.
getdate.sql
select sysdate from dual;getdate.sh can look like this
sqlplus user/pwd @getdateor
sqlplus user/pwd <<EOSQL
@getdate
EOSQLor
sqlplus user/pwd <<EOSQL
select sysdate from dual;
exit
EOSQLMy preference would be for either of the first two.
You can use various shell facilities to capture the output of the sql statement for use elsewhere. Variations of the above example can be use to get the current database date and time into the shell environment for use in other queries, or in the shell itself.
You can run SQL Developer from the command line, but the tool of choice for command line is SQL Plus. -
General Inquiry Regarding Error Handling with System Exec.vi
I have a sub vi that uses the System Exec.vi to send SMS messages when triggered. I am confused as to how the error handling works and why all of the errors seem to go to the "standard error" vs the "Error out". The reason I am interested is because I am trying to interrupt the error out of another script to execute a command if error=true.
I have intentionally created an error to test this, however it does not seem that the signal is ever being sent to the error out, only to the standard error.
Any help/explanation as to how this works would be greatly appreciated.The Facebook discussion board is just a pilot and that functionality is not available yet (as to my knowledge). You will have to use the actual forum thread to add attachments. You can click the arrow just to the right of thread topic in the Facebook thread and that will take you to the ni.com/forums thread. Or you can navigate here:
http://forums.ni.com/t5/LabVIEW/General-Inquiry-Regarding-Error-Handling-with-System-Exec-vi/m-p/246...
Having a look at your VI would help to clarify the error handling issue.
Daniel K | NI Applications Engineer | Certified LabVIEW Developer -
RMAN errors sent to shell script calling RMAN sequence?
Hello,
I have a Korn shell script run on Solaris as the root user that launches RMAN sequences similar to this one:
#!/bin/ksh
su - oracle -c "export ORACLE_SID=ORCL; rman target / << !
<rman sequence>
I am wondering if there is a way to catch the RMAN errors in the shell script?
If I call SQLplus instead of RMAN, I can use "whenever sqlerror exit sql.sqlcode" and I will retrieve the error code in the shell script from $? - can I do such a thing with RMAN?
Thank you,
AdrianYou could capture the return code *$?* from your RMAN script and if it returns anything other than 0, then you could grep the RMAN log for errors and/or query
V$RMAN_OUTPUT after the RMAN script executes. -
Step by Step documents for Process Chain Error Handling with Screen Shots
Hi
Is anybody having Step By Step Documents for Process Chain Error Handling with Screen Shots ?. Please forward it to me to my e-mail [email protected] . I will reward points to u immediately.
bye
Aamira KhanHi,
You can find lots of topic related to process chain issues in SDN.Please make a search in SDN.
https://www.sdn.sap.com/irj/sdn/advancedsearch?cat=sdn_library&query=process+chain&adv=true&sdn_author_name=&sdn_updated_on_comparator=ge&sdn_updated_on=&sortby=cm_rnd_rankvalue
Regards. -
Hi,
Can any one explain please
1.Why we need to create XSD,
2.What is the use of dehydration,
3.Types in XML
Please explain any error handling with example.Hi',
1.Why we need to create XSD,
This is used as the input/output for the webservice/BPEL
2.What is the use of dehydration,
This is used to save the state of the composite/BPEL/Mediator in the database
3.Types in XML
complex, simple
Error handing in file
http://yatanveersingh.blogspot.com/2011/09/fault-handling-in-file-adapter-for-csv.html
-Yatan -
Need to enable Usage Tracking With Shell Script
Hi All
I have patch 11.1.1.6.7 installed in system. I have Redhat linux 6 sytem
Can we enable usage tracking with shell script ? if yes how ?
Thanks
Samit BaghlaHi Samit,
No you can not as per my info because everything to be configured for the usage tracking is via repository and enterprise manager. You need to invoke it in em and rpd you need to do modelling. I still did not understand that why you want to create the shell script !!
Thanks,
Amol
(Please mark this answer, if you found correct) -
Error Handling with sql *plus from a shell script
When I execute sql plus in a shell script with the wrong username/pass pair, the shell script hangs without terminating. What is the proper way to execute sql plus in a shell script that will catch a login failure and make sure the script doesn't hang?
Example:
We execute the following in our shell script:
sqlplus ${ORACLE_INST} @./sql/ftp_ledger_put.sql
Now if somebody comes along and alters the login then the script would hang. Is there a way to have the script exit gracefully?Not the most elegant solution but.......
sqlplus <<EOD 2>&1 >some_log_file
user/pwd
@somescript
exit
EOD
Because sqlplus allows for 3 tries at log in if user/pwd is not valid it will try to use subsequent lines. Each will fail.
You have to look in some_log_file to determine success/failure
Ken -
Dbms_scheduler error when running shell script
I have 2 shell scripts.
ftp_file_from_apps.sh copies a file from one server to antoher. It receives an input which is the name of the file to be copied.
scp_file_to_dbs.sh does a secure copy. Copying the file fo anther directory on the same server.
ftp_file_from_apps.sh
~~~~~~~~~~~~~~~~~
#!/bin/bash
sftp applprod@<host.domain>:/<source_directory>/$1
/<destination_directory>/$2
scp_file_to_dbs.sh
~~~~~~~~~~~~~
scp -r /<source_directory>/$1 <host.domain>:/<destination_directory>/$1
Both of these scripts works 100% when i run them from os level:
ftp_file_from_apps.sh xxx.out xxx.pdf
scp_file_to_dbs.sh xxx.pdf
the problem is when i run them with dbms_scheduler:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
v_file_name and v_file_name_pdf is varchar2(20) with values assigned.
begin
dbms_scheduler.create_job(
job_name=>'FTP_FILE_FROM_APPS',
job_type=>'executable',
job_action=>'/<directory_of_script>/ftp_file_from_apps.sh
v_file_name v_file_name_pdf',
enabled=>TRUE
end;
begin
dbms_scheduler.create_job(
job_name=>'SCP_FILE_TO_DBS',
job_type=>'executable',
job_action=>'/<directory_of_script>/scp_file_to_dbs.sh
v_file_name_pdf',
enabled=>TRUE
end;
ftp_file_from_apps.sh error:
ORA-27369: job of type EXECUTABLE failed with exit code: No such file or directory
scp_file_to_dbs.sh error:
ORA-27369: job of type EXECUTABLE failed with exit code: No such file or directory
I tripple checked my <directory_of_script>.
Please help.
Regards
JohnHi,
What Paul means is that you should not be using
job_action=>
'/<directory_of_script>/scp_file_to_dbs.sh v_file_name_pdf',
Instead job_action should be the name of the shell script only. So you should have
job_action=>
'/<directory_of_script>/scp_file_to_dbs.sh',
number_of_arguments=>1
enabled=>false
And then make a call to dbms_scheduler.set_job_argument_value (for each argument) and finally a call to dbms_scheduler.enable.
Hope this helps,
Ravi. -
Hi,
I am executing on procedure using the shell script. The Shell script would the spool the output of the procedure into Status.txt file and send the condents through the mail. I am getting correct output when i run the job manually. But it is not giving the output when the job is scheduled in Crontab. Please find the below my shell script.
ORACLE_SID=ora
export TNS_ADMIN=/oracle/11.2.0/network/admin
export ORACLE_HOME=/oracle/11.2.0
export PATH=/oracle/11.2.0/bin:$PATH
export LIBPATH=/oracle/11.2.0/lib32:$LIBPATH
sqlplus -s test/test@test << EOFSQL
SET HEAD off
SET LINESIZE 8000
SET feedback OFF
SET pagesize 0
SET termout OFF
SET SERVEROUTPUT ON
SPOOL Status.txt
begin JobStatus();
end;
SPOOL off
SET termout ON
exit;
EOFSQL
TO='EmailID'
file=/myFolder/Status.txt
cat $file|mailx -s "Status" ${TO}The only PATH a user cron job knows by default is "/usr/bin" and "/bin", hence it won't find any Oracle applications. ORACLE provides a tool named "oraenv" to setup the required Oracle shell environment. oraenv reads /etc/oratab to setup $ORACLE_HOME, etc. It is by default installed in /usr/local/bin. The following example should work:
#!/bin/sh
# Filename: /home/oracle/scripts/sqlplus_sample.sh
# Author: dude
PATH=/usr/local/bin:$PATH
export $PATH
ORACLE_SID='orcl'
ORAENV_ASK=NO
. oraenv -s
oradate=`sqlplus -s /nolog <<-EOF
set pages 0 feed off
connect / as sysdba
select sysdate from dual;
exit
EOF
`
echo "`date`: Oracle $oradate" >> /tmp/sqlplus_sample.output
[oracle@vm10]$ chmod 755 /home/oracle/scripts/sqlplus_sample.sh
[oracle@vm10]$ crontab -l
* * * * * /home/oracle/scripts/sqlplus_sample.sh
[oracle@vm10]$ cat /tmp/sqlplus_sample.output
Mon Dec 12 11:27:01 CET 2011: Oracle 12-DEC-11
Mon Dec 12 11:28:01 CET 2011: Oracle 12-DEC-11
Mon Dec 12 11:29:01 CET 2011: Oracle 12-DEC-11
Mon Dec 12 11:30:01 CET 2011: Oracle 12-DEC-11Btw, exporting a shell variable means to make it available to sub-shells or child processes.
Also, depending on how you connect, you don't need to export TNS_ADMIN. If you establish a local connection you will be connecting to the oracle database process directly using the BEQ protocol, in which case you don't even need a listener process running. For instance:
$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.2.0 - Production on 12-DEC-2011 12:10:29
Copyright (c) 1991, 2010, Oracle. All rights reserved.
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
TNS-12541: TNS:no listener
TNS-12560: TNS:protocol adapter error
TNS-00511: No listener
Linux Error: 111: Connection refused
$ sqlplus scott/tiger
SQL*Plus: Release 11.2.0.2.0 Production on Mon Dec 12 15:05:57 2011
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options -
Error handling with selecting new lines
Hi All,
Please help me on this.
Step 1 : Enter transaction MD07.
Material : 312507
MRP Area : w8prod
PLant : w8
Step 2 : Double click on "PurRqs".
Step 3 : Click on -> Purchase order button.
While recording i will follow this procedure,if i again execute the same scripts it will double click on same "PurRqs".
But what i needed is that it has to click on next line.ie.,new "PurRqs".
How will i solve this Error handling?
Regards,
SamHi kiran,
Thanks for the reply.
Now you can able to execute step 2.
Double click on PurRqs(0013201371) and try to execute.
My question is if i try to record with this PurRqs(0013201371) then if i again execute it has to take new PurRqs(0013201372).
How to handle this parametrization.
Script name : Z_MM_PACKAGING_27_TS
Facing problem in this command : SAPGUI ( SAPGUI_9_1 ).
So please help me on this.
Regards,
Sam -
Packagemaker with shell-script?
I pulling my hair here. Trying to make a package with a shell-script, postinstall. When i try to choose it its greyed out so i cant select it at all. permissions are root:admin and 0555, i have no clue whats wrong anymore and i have searched the whole internet!
Using Tiger with Xtools 2.1.
Happy for all suggestions.
thx1) If you have access to a Windows machine , run the problematic query in windows 'rwrun' and see whether there is any output That way we can find out whether this a 'shell' related problem . [ ie the way cmd lines are passed ]
2) Backup and Edit the rwrun.sh script . There you can see
rwrun $* # or something to this effect
Instead of '$*' , put your command line args inside directly .
Then just simply run using rwrun.sh < no args >
Again , this is to see whether this problem is due to the way shell handles parameters
3) You can even try setting env variables [ as in reports.sh ] and trying 'rwrun' in shell prompt itself
rwrun <.....> # no .sh
4) Please consult SuSe shell docs and see whether % [ or may be ' and \ ] has any special meaning.
Thanks
The Oracle Reports Team -
Can anyone here help me (getting my feet wet) with an addition to a profile (applmgr) that I am trying to make - in the form of a shell script.
I have the following lines in the profile file - but each time I log into the server as applmgr, I get the error following
if $HOSTNAME=hostname1
tnen
. /u01/xxees/EBST/apps/apps_st/appl/APPSEBST_$HOST.env
fi
if $HOSTNAME=hostname2
./u01/xxees/EBST2/apps/apps_st/appl/APPSEBST_$HOST.env
fi
The error message I am getting us
-bash: /local/ebsuser/applmgr/.profile: line 39: syntax error near unexpected token `fi'
-bash: /local/ebsuser/applmgr/.profile: line 39: `fi'
Thank you all.
Edited by: 864641 on Jun 13, 2012 1:49 PMFrom the Error Message at line Number 38, I feel that, the file /u01/xxees/EBSTEST/apps/apps_st/appl/APPSEBST_$HOST.env (where $HOST can be "hostname01" or "hostname02") has been modified and has unmatched if.
Also, If you are using the variable HOSTNAME, I feel that the env file should be like /u01/xxees/EBSTEST/apps/apps_st/appl/APPSEBST_$HOSTNAME.env in which case your script will be like:
if [$HOSTNAME == "hostname01"]; then
. /u01/xxees/EBSTEST/apps/apps_st/appl/APPSEBST_$HOSTNAME.env
fi
if [$HOSTNAME == "hostname02"]; then
. /u01/xxees/EBSTEST2/apps/apps_st/appl/APPSEBST_$HOSTNAME.env
fi
Hope that this two things will help in resolving the issue. -
Execve: Exec format error to execute shell script
I made job to execute a shell script.
exec dbms_scheduler.create_job (
job_name => 'run_sh',
job_type=>'EXECUTABLE',
job_action=> '/fsoracle/app/oracle/inst2/if_cft/send_file_susin.sh',
start_date=>sysdate + 1/5760,
enabled => TRUE
send_file_susin.sh
#!/bin/ksh
set -v
. /fsutil/ndm/axway/profile
/fsutil/ndm/axway/Synchrony/Transfer_CFT/bin/CFTUTIL << EOJ
CONFIG TYPE=COM,MEDIACOM=TCPIP,FNAME=$CFTTCP
SEND PART=ZADA,IDF=1363X1364,
FNAME='/fsoracle/app/oracle/product/rdbms/log/KFG.DD.SHRCOM.HRD.A03',
NFNAME=KFG.DD.SHRCOM.HRD.A03,
FLRECL=25,NLRECL=25
SWAITCAT SELECT='IDTU=="%_CAT_IDTU%"'
EOJ
This script is well executed in terminal mode, but it threwed error, [ORA-27369: job of type EXECUTABLE failed with exit code: Unknown error STANDARD_ERROR="execve: Exec format error"] when I executed the shell script, send_file_susin.sh.
I changed owners and chmods of some specific files, and t.sh was well executed.
t.sh
#!bin/ksh
/usr/bin/mkdir /tmp/test
I don't know what's wrong with the script, send_file_susin.sh.
Does any know about this? Please, tell me the solution.
Thanks in advance,
Jinbae Kim.Hi,
Posting this in case anyone else find it.
The key error here is "execve: Exec format error" .
The following things should be checked
- that the shell script is a text file has UNIX line terminators
- that the shell script is set to be executable by the user that the job runs as
- that the shell script begins with a hashbang line - e.g. #!/bin/sh (I suspect this is the problem)
For running external jobs on 10gR2 or below, refer to this post Guide to External Jobs on 10g with dbms_scheduler e.g. scripts,batch files
For running external jobs on 11g and up, please use a credential.
Hope this helps,
Ravi.
Maybe you are looking for
-
I have an iPod 4th gen and the bottom part of it doesn't work where the space, .?123, and the go buttons are not working I droped it yesterday but it started doing this an hour ago I can slide to get in but it's stops working after that someone tell
-
Clarification required as to installing Arch Linux onto Macbook Pro
I own a 13 inch Mid 2010 Macbook Pro with the base configuration. When partitioning my hard drive what hexadecimal flag should the 100 MiB boot partition be given and what format should it be formatted to? Also upon running iwconfig wlan0 does not ap
-
Error in Oracle Form 10g while deploying it on Application server
hiiiii I have a form in 10g in which i am trying to produce data in excel format through ole2.. the form is working fine when i am running it on form builder....but when i deploy this form on oracle 10g application server,the form is getting run thro
-
I got My iPhone 4s and restored using an Old Backup of my 3Gs
Out of the box the iPhone 4s started fine. I synced it without a problem refering to a previous backup of my iPhone 3Gs. Network issues meant I did not use it as my primary phone for 4 days and phone still had my apps and old contacts. When I finally
-
1st gen shuffle uploading songs
I just got a first gen ipod shuffle. It said in the manual to is it like a flash drive. So i took music from my itunes, and copied it straight to the ipod. When i took the ipod out i pressed the eject button. Then i took the ipod out. I tryed to play