Shell script to execute Oracle procedure and trigerring email on success and failure
Here is the shell script which need to trigger a stored procedure and when the record count is 0 then it should capture in the log that 0 duplicate records are found and if it's more than 0 then log with no of records. Also if there is any sqlerror then it should write the same in the log file and it should send the communication in all scenarios. We have funct file which has declared with all directories and we are referring here for the log file path directory. But when i tried to execute it getting this error message not found [No such file or directory] - ./local/dir1/funct.sh. Also can you help me out in the code logic as well?
Firstly I would suggest that you move the credentials to within the here document like this:
The way you have it exposes the credentials to anyone who manages to run ps whilst the sqlplus command is running each time.
You can even neaten this further by avoiding the output file:
As to your actual question over the 'not found' response (for which I've wrapped it in ICODE tags in your post) this is probably because the file is relative to your current working directory. If you doa pwd then think about where that file is relative to where you are thne it might become clearer. Can you set an absolute path (i.e. starts with a leading slash for the root directory) and try again? Does this get you anywhere further?
I hope tha these suggestions help,
Robin
Last edited by rbatte1; 12-19-2019 at 08:24 AM..
Reason: Properly aligning comments
I tried with the same code by giving the exact path for funct.sh. Now that error not found [No such file or directory got rectified but it's not connecting with Oracle and not executing the proc. Moreover am getting email message that No Duplicate records Found: though the result of this query fetches 800 records.
Also I tried with other version of code with your suggested changes and got the error message like this
Also , i'd like to have an accurate mechanism to store the return value of procedure to the shell script. Here my requirement is to execute a stored procedure from this shell script once done i need to trigger the emails based on their success with the record counts and if not return with sql error if any.Could you please help me on this?
Please can you post the code you ran to generate the error. It might be that the comments get in the way, so perhaps strip them out and try again too.
An alternate might be to return a complex string listing the return code and data values, then afterwards your script can separate out which means which. I do this for commands driven remotely by ssh connections. It's not pretty, but it works quite reliably.
Thanks for your reply Robin. Here is the modified code. Also could you assist me in how to store the return value of procedure to the shell script.Here the variable V_COUNT value is not returning to the shell script. Could you please give an example on this?
Your first active line calls another script. Is that meant to load functions in for you? I'd suggest preceding it with the word source else any variables set and the functions defined will be lost when the script exits.
Line 18 exectuing chmod 777 "${LOG_FILE}" looks a little dubious. Would you really want anybody with access to the OS to be able to read your log (maybe), edit your log (not very likely) and potentially execute your logfile (almost certainly not)?
Does line 20 have a spelling mistake with ssqlplus?
Is line 36 calling a stored procedure? What's inside that? Does it end with a zero return code?
How do you know that there has been a failure, or is that just zero rows counted?
Outside of the embedded SQL, you refer to ${v_count} which only seems to be set within the embedded SQL, i.e. will only exist when the SQL process is running. It may be as simple as exiting from the SQL using that.
Have you considered finishing the SQL part with exit &v_count perhaps? It might be just as simple as that and you shell script will get the $? as the value of &v_count unless you abort early and return the value -1, of course.
Hi ,
I am trying to automate a gather stats in shell script
#!/usr/bin/ksh
export ORACLE_HOME=/orcl/app/oracle/product/11.2.0.1/db_1
export PATH="$PATH:$ORACLE_HOME/bin"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$ORACLE_HOME/lib32"
export TNS_ADMIN=/opt/netprobe/config... (1 Reply)
i have the following code inside a shell script .prog in oracle server when i call the program
DBMS_OUTPUT.PUT_LINE(x_return_status|| ln_rep_req_id);
will return 0 , it is very strange , i try to submit the concurrent request in oracle , and it can successfully executed, what am i missing ? i... (1 Reply)
Hi Gurus,
Want to execute a shell script from a oracle procedure and get the status of the same, any assistance in this regard will be appreciated.
proc_data.sh is script name which I want to execute from oracle procedure
It should work something like below
procedure test
begin... (1 Reply)
Hi everyone!
I'm new with Shell Scripting, and I have to do a shell script to call a procedure, which have 2 input parameters, the directory(from server) and the txt file (which have informations to update/insert in DB).
I have to create a shell script to execute that procedure for each txt... (5 Replies)
Here's a shell script snippet.....
cd $ORACLE_HOME/bin
Retval=`sqlplus -s <<eof
$TPDB_USER/april@$TPD_DBCONN
whenever SQLERROR exit 2 rollback
whenever OSERROR exit 3 rollback
set serveroutput on
set pages 999
var status_desc char(200)
var status_code... (1 Reply)
Hi ,
i have created an .sh file that has the following code:
#!/bin/ksh
sqlplus -s p1istuat/p1istuat@CWS_IST6 @Procedure_Execute.sql &
sqlplus -s p1istuat/p1istuat@CWS_IST6 << EOF
exit
EOF
The mentioned Procedure_Execute.sql file inside has the following code:
exec TEST;
... (5 Replies)
hai,
can anybody say how to call or to execute an oracle stored procedure in oracle from unix...
thanks in advance.... for ur reply....
by,
leo (2 Replies)