Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Emailing results of a pl sql procedure from UNIX shell script Post 302962721 by Bunty bedi on Thursday 17th of December 2015 05:22:41 PM
Old 12-17-2015
Well , let me post my real requirement.
the script will select all the records from a table with the condition timestamp=(sysdate-1 hr). once the records are selected, it will check the flag value of each record and if the record matches a particular flag value, it will send out an email.
i want to accomplish this task in the shell script itself without using any additional files.
is this feasible?
i am a newbee to unix and doesn't have much knowlegde.

---------- Post updated at 05:22 PM ---------- Previous update was at 04:36 PM ----------

here is my sample script

Code:
#!/bin/bash
ORACLE_HOME=/opt/oracle/orcts/product/9.2.0; export ORACLE_HOME
SQLPLUS=$ORACLE_HOME/bin/sqlplus

sqlplus -s user/pass@db_inst <<EOF
set echo off head off feed off pagesize 0  trimspool on linesize 1000
spool result.csv
select rownum,emp_id,emp_name from employees where dept_no=2;
spool off
exit;
EOF
a=1
b=2
while read f1 f2 f3
do

if  $f1 -eq $a
then
echo "this is first test email for employee id= $f2 with name =$f3" | mailx -r abc@gmail.com -s "test email 1" xyz@gmail.com
elif $f1 -eq $b
then
echo "this is second test email for employee id= $f2 with name =$f3" | mailx -r abc@gmail.com -s "test email 1" xyz@gmail.com
fi

done < result.csv

getting the following errors on executing

Code:
test.sh[17]: 1: Execute permission denied.
test.sh[21]: 1: Execute permission denied.
test.sh[17]: 2:  not found.
test.sh[21]: 2:  not found.

it runs perfect without the if else decision making. and there are only 2 records in the result of my sql query.

Please help

Moderator's Comments:
Mod Comment edit by bakunin: CODE-tags please!

Last edited by bakunin; 12-18-2015 at 01:22 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

return variable from PL/SQL procedure to shell

Hi i'm calling a pl/sql procedure which is returning one variable. i'm trying to assing this value to variable in shell script the code i wrote is ** in shell script** var= 'sqlplus user/pass @ret.sql' echo $var ** and variable dum_var number exec rt_test(:DUM_VAR); exit; in... (4 Replies)
Discussion started by: ap_gore79
4 Replies

2. UNIX for Dummies Questions & Answers

Running PL/SQL procedure via unix

All, I have a 10g PL/SQL procedure that needs to be run via a unix script. How could such a script be developed. Thanks Aditya. (1 Reply)
Discussion started by: kingofprussia
1 Replies

3. UNIX for Dummies Questions & Answers

sql query results in unix shell script

Hi I want to get the a field from a SQL query into unix shell script variable. the whole situation is like this. 1. Opened a cursor to a table in DB2 databse. 2. Fetching individual rows with the help of cursor. 3. Each row has 4 fields. I want each of the field in individual shell... (1 Reply)
Discussion started by: skyineyes
1 Replies

4. Shell Programming and Scripting

Calling an Oracle Stored Procedure from Unix shell script

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)
Discussion started by: Leojhose
2 Replies

5. Shell Programming and Scripting

How to compile a stored procedure that is there with in a script file(.sql) in unix

Hi, How can i compile the procedure code that is there in a script file (.sql) in unix. (0 Replies)
Discussion started by: krishna_gnv
0 Replies

6. Shell Programming and Scripting

Invoking Oracle stored procedure in unix shell script

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)
Discussion started by: hidnana
1 Replies

7. Shell Programming and Scripting

Passing a value to stored procedure from unix shell script

Hi Dudes :) I want a unix shell script to pass value to SQL stored procedure. Below is the procedure declare res varchar2(10); begin odm_load_check('PRE_SANITY',res); dbms_output.put_line(res); end; select * from error_log; truncate table error_log; select * from test; (1 Reply)
Discussion started by: shirdi
1 Replies

8. Shell Programming and Scripting

How to Pass the Output Values from the PL/SQL Procedure to Shell Script?

hi, Could anyone tell me how to pass the output values of the PL/SQL procedure to Shell script and how to store that values in a shell script variable... Thanks in advance... (5 Replies)
Discussion started by: funonnet
5 Replies

9. Shell Programming and Scripting

Export SQL results to .TXT file for emailing

Hi everyone, I am new to unix and bash and in need of some help. I am writing a script that will execute a SQL query. The script runs and the SQl query runs, but I cannot figure out how to save the results as a file that can be emailed to a user. Here is my scripts thus far: #!/bin/sh SID=$1... (2 Replies)
Discussion started by: alpinescott
2 Replies

10. Shell Programming and Scripting

Recompile PL/SQL Procedure through UNIX

Hi, We have a procedure e.g. prc_synonym created in Oracle 12c Database. I want to do small change in procedure through Unix. I have that changed procedure (prc_synonym) in proc.sql file. Want to recompile that procedure through Unix so that changes should reflect in existing procedure in... (10 Replies)
Discussion started by: Aparna.N
10 Replies
INITSCRIPT(5)						Linux System Administrator's Manual					     INITSCRIPT(5)

NAME
initscript - script that executes inittab commands. SYNOPSIS
/bin/sh /etc/initscript id runlevels action process DESCRIPTION
When the shell script /etc/initscript is present, init will use it to execute the commands from inittab. This script can be used to set things like ulimit and umask default values for every process. EXAMPLES
This is a sample initscript, which might be installed on your system as /etc/initscript.sample. # # initscript Executed by init(8) for every program it # wants to spawn like this: # # /bin/sh /etc/initscript <id> <level> <action> <process> # # Set umask to safe level, and enable core dumps. umask 022 ulimit -c 2097151 PATH=/bin:/sbin:/usr/bin:/usr/sbin export PATH # Increase the hard filedescriptor limit for all processes # to 8192. The soft limit is still 1024, but any unpriviliged # process can increase it's soft limit up to the hardlimit # with "ulimit -Sn xxx" (needs a 2.2.13 or later Linux kernel). ulimit -Hn 8192 # Execute the program. eval exec "$4" FILES
/etc/inittab, /etc/initscript. AUTHOR
Miquel van Smoorenburg ,<miquels@cistron.nl> SEE ALSO
init(8), inittab(5). December 24, 1999 INITSCRIPT(5)
All times are GMT -4. The time now is 12:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy