Problem running plsql & unix commands in 1 script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Problem running plsql & unix commands in 1 script
# 1  
Old 10-04-2006
Problem running plsql & unix commands in 1 script

Hi, I need help again. When I run this shell script, it only runs the unld_date.sql piece and exits. How can I structure this to run all the way to the end? When I don't have the unld_date.sql piece in here, everything runs fine from the date compare piece all the way to the end. Thanks in advance.


#!/bin/sh
#
sqlplus -s <<EOF username/password @/dir1/unld_date.sql > /dir2/dt_file.dat
exit 0
#
dt=`cat dt_file.dat`
today_dt=`date +%m%d%Y`
if [ "$dt" = "$today_dt" ]
then
#
# run pl/sql procedures 1 and 2
sqlplus -s <<EOF username/username @/dir3/code1.prc > /dir4/code1.log
@/dir3/code2.prc > /dir4/code2.log
exit
EOF
#
tail -10 /dir4/code1.log > log1.txt
tail -10 /dir4/code2.log > log2.txt
#
exit
# 2  
Old 10-04-2006
Am I missing something?

If this is really how your script reads, the "exit 0" is going to terminate your script every single time once "unld_date.sql" has been executed.

If it is working with "unld_date.sql" removed then you must also be removing "exit 0". The "exit 0" statement is not tied to the sqlplus command.

So the simple answer to your question is to remove "exit 0".
# 3  
Old 10-05-2006
I have taken out the "exit 0" line and it still gives me the same result. It stops right after the unld_date.sql and doesn't execute the rest. Thanks.
# 4  
Old 10-05-2006
Try EOF

where you have the exit 0, try putting EOF. Im a newb, but I think when you use <<EOF it expects anything between that and EOF to be commands within the program you started before the <<EOF.
# 5  
Old 10-05-2006
Quote:
Originally Posted by redwjamz
where you have the exit 0, try putting EOF. Im a newb, but I think when you use <<EOF it expects anything between that and EOF to be commands within the program you started before the <<EOF.
I agree.
I think your script should read:
Code:
[...]
sqlplus -s <<EOF 
username/password @/dir1/unld_date.sql > /dir2/dt_file.dat
exit
EOF
[...]

Though it seems incomplete... I miss a "fi" and there are also an "exit" that, in my opinion, does not fit (the last one)...

Regards.
# 6  
Old 10-05-2006
Quote:
Originally Posted by siog
#!/bin/sh
#
sqlplus -s <<EOF username/password @/dir1/unld_date.sql > /dir2/dt_file.dat
exit 0
#
dt=`cat dt_file.dat`
today_dt=`date +%m%d%Y`
if [ "$dt" = "$today_dt" ]
then
#
# run pl/sql procedures 1 and 2
sqlplus -s <<EOF username/username @/dir3/code1.prc > /dir4/code1.log
@/dir3/code2.prc > /dir4/code2.log
exit
EOF
#
tail -10 /dir4/code1.log > log1.txt
tail -10 /dir4/code2.log > log2.txt
#
exit
Looking at the script again, the answer is clear. You are attempting to use a "here" document with the "<<EOF" statement. Your entire script is being pushed into sqlplus and when it reaches the "exit 0" command, it is exiting and the rest of your script isn't processed by sqlplus, which is why you don't see any error in you code1.log file.

You either need to add the "EOF" as stated by other posters or remove the "<<EOF". sqlplus will run the SQL at this point and let your script continue.
This User Gave Thanks to tmarikle For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem running plsql using printf command on bash shell

I am running plsql using printf on a shell, but i am getting some strange error, can someone point what exactly am i missing, $ echo $SHELL /bin/bash $ printf " > SET serveroutput ON trimspool on feed off echo off > declare > p_val number; > d_val varchar2(10); > begin > SELECT... (1 Reply)
Discussion started by: kamauv234
1 Replies

2. Shell Programming and Scripting

Problem running db2 commands in awk

Hi , I am trying to use the below in awk but failed, any one assist please, awk '{ print $0; if ( $0 ~ /LOADTMP1/ ) { print $4; Table_name=system($( db2 -x "SELECT TRIM(TD.BSCHEMA) || '.' || TRIM(TD.BNAME) AS TABLE_NAME FROM SYSCAT.TABDEP TD WHERE TD.BTYPE='T' AND... (2 Replies)
Discussion started by: Nandy
2 Replies

3. Shell Programming and Scripting

How to pass value from plsql script to unix bash?

Hi This is my bash script.i am calling validation.sql and passing a value to it using ${flds}. i want the cnt variable in plsql script to be passed to unix. LOADREC=`sqlplus -s $ORACLE_USR <<-EOF spool $ORACLE_LOG_FILE; echo "barani" @validation.sql #calling the plsql script ${flds}... (6 Replies)
Discussion started by: barani75
6 Replies

4. Shell Programming and Scripting

Running unix commands in a perl script

Executing two unix commads via perl script one after another e.g: make clean bsub -i -q short make have tried using exec but the second command doesnt executes (1 Reply)
Discussion started by: rajroshan
1 Replies

5. Shell Programming and Scripting

Running multiple unix commands in a single script

Hi, I would like to write a script with include more than 6 unix commands. my script like below: echo " script started" ls -ld bdf | grep "rama" tail -10 log.txt ... .. ... now, i want to run above unix commands one by one. example: first the ls -ld command will be... (3 Replies)
Discussion started by: koti_rama
3 Replies

6. Programming

running PLSQL scripts through shell script

I am running the following ealth checks on my server there are two databases in my server . MODEL1 and MODEL2 i connect with the first database as sqlplus model1/password Then i exceute a query select x from table (4 Replies)
Discussion started by: asalman.qazi
4 Replies

7. Programming

UNIX Shell Script to Create a Document of a PLSQL code.

Hi All, I am supposed to present the documentation for the PLSQL code (PACKAGES, PROCEDURE, FUNCTIONS) of my application. There are sufficient comments in my code. Has anyone written any Shell Script Utility which can parse the PLSQL code and generate some kind of document ( preferrably HTML not... (1 Reply)
Discussion started by: gauravsachan
1 Replies

8. UNIX for Advanced & Expert Users

Calling unix script from sql or plsql

Hi Can anyone please let me know how to call unix scripts from sql or plsql ASAP. (2 Replies)
Discussion started by: ksailesh
2 Replies

9. Programming

Running UNIX Commands from C

Hi, -How can I get number of files, cpu usage (percentage), memory usage, disk usage, ...etc, using C program ... I can use unix command ( system(command) )but I want the value to be returned back to my C program to use it in my code? How can I do that? Thanks in advance ... (2 Replies)
Discussion started by: zainab
2 Replies

10. UNIX for Advanced & Expert Users

calling plsql function in a unix script

Could anyone please help me. I have a function in plsql that returns a number. But i am listing some records through that function using DBMS_OUTPUT.PUT_LINE. I want to catch those records by executing this function through a unix script. The following shows what i did echo "Connected from... (2 Replies)
Discussion started by: cobroraj
2 Replies
Login or Register to Ask a Question