Calling sqlplus from Korn shell heredoc issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Calling sqlplus from Korn shell heredoc issue
# 1  
Old 01-21-2014
Calling sqlplus from Korn shell heredoc issue

Hi,
I am facing an issue wherein some temporary files (here docs) are getting created in /tmp and are not getting deleted automatically.
When i check the list of open files with below command i can see one file is getting appended continuously.(In this case /tmp/sfe7h.34p)
The output is something like below:
Code:
bash-3.2$ /usr/sbin/lsof | grep '/tmp' | grep '(deleted)'
sh_test 13107     test    0u      REG    8,3      224   1782884 /tmp/sfe7h.34p (deleted)
sh_test 13107     test    1u      REG    8,3        0   1782887 /tmp/sffak.tri (deleted)

Due to this the /tmp mount point is getting full causing trouble to application.
Following is the pseudo script which runs continuously monitoring status of application and then performs some tasks.
Code:
#!/bin/ksh
get_app_status(){
result=`sqlplus -s user/password@servicename <<EOF
whenever sqlerror exit sql.sqlcode
set escape off
set head off
set verify off
set feedback off
select param_value from status where param_name='app_status'
EOF
`
echo $result
}

while [ `get_app_status` = 'Started' ]; do
#Some logic here
done

The issue won't occur if we remove the first line shell interpreter(#!/bin/ksh) or we call the get_app_status once or twice and not in loop.
Korn shell version is:
version sh (AT&T Research) 93s+ 2008-01-31
Any help in understanding the cause is deeply Appreciated.

Thanks,
Navin
# 2  
Old 01-21-2014
Those files have been deleted as indicated by "(deleted)". But, as the command/script/program that created and populated them is still running and keeps them open, their data and meta data on disk can't be released.
Try closing them by e.g. changing the redirection in your script, and - voila - they'll disappear.
# 3  
Old 01-21-2014
Thanks RudiC.

Not sure how we can change the redirection in script. Please suggest.
# 4  
Old 01-21-2014
For example just
Code:
exec > /tmp/newfile

within the script. May be wise to change the filename every now and then.
# 5  
Old 01-22-2014
The script works fine with below changes. Temporary heredoc files are getting created and subsequently deleted for each DB call
Code:
#!/bin/ksh
get_app_status(){
eval `result=`sqlplus -s user/password@servicename <<EOF
whenever sqlerror exit sql.sqlcode
set escape off
set head off
set verify off
set feedback off
select param_value from status where param_name='app_status'
EOF
`
`
echo $result
}

while [ `get_app_status` = 'Started' ]; do
#Some logic here
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Control not returning from Sqlplus to calling UNIX shell script.

Hello All, I have exactly same issue @vikas_trl had in following link: https://www.unix.com/shell-programming-and-scripting/259854-control-not-returning-sqlplus-calling-unix-shell-script.html I wonder if he or somebody else could find the issue's cause or the solution. Any help would... (4 Replies)
Discussion started by: RicardoQ
4 Replies

2. Shell Programming and Scripting

Control not returning from Sqlplus to calling UNIX shell script.

Hello All, I have a UNIX script which will prepare anonymous oracle pl/sql block in a temporary file in run time and passes this file to sqlplus as given below. cat > $v_Input_File 2>>$v_Log << EOF BEGIN EXECUTE IMMEDIATE 'ALTER SESSION FORCE PARALLEL DML PARALLEL 16'; EXECUTE... (1 Reply)
Discussion started by: vikas_trl
1 Replies

3. Shell Programming and Scripting

[Solved] Issue with using for loop as for in {2..6} in korn shell

Hi i have to cut columns 2 to 6 from a file and assign it to arrays , The following code works for ctcol in 2 3 4 5 6; do set -A a$ctcol $(cut -d, -f $ctcol test_file) done how ever this does not work for ctcol in {2..6}; do set -A a$ctcol $(cut -d, -f $ctcol test_file)... (4 Replies)
Discussion started by: 100bees
4 Replies

4. Shell Programming and Scripting

Multithreading - Calling user function with xargs in korn shell

I know there are other ways of accomplishing the below task, but the purpose of this thread is to understand the below code. I wanted to use xargs with user defined function in korn shell. Am aware, that I could write custom function into a script and place it in FPATH and then call it in xargs,... (2 Replies)
Discussion started by: luhah
2 Replies

5. Shell Programming and Scripting

korn shell for loops with expect issue

Hi I have the following Korn script having multiple for loops. #!/bin/ksh EXPECT=/usr/local/bin/expect exp_internal for d in 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 i22 23 24 25 26; do for i in 01 02 03 04 05 06 07 ; do for h in 00 01 02 03 04 05 06 07 08 09 10 11 12... (2 Replies)
Discussion started by: cic
2 Replies

6. UNIX for Advanced & Expert Users

Calling PERL from a Korn shell script

I am currently in Afghanistan and do not have access to some of the resources I normally do back in the US. Just accessed this site and it looks promising! Hopefully you will not find my question too much of a waste of your time. I write mostly Korn Shell and PERL on Solaris systems for the... (2 Replies)
Discussion started by: mseanowen
2 Replies

7. UNIX for Dummies Questions & Answers

calling a unix shell script from sqlplus

I want to execute a shell script from sqlplus prompt and get its output back to sqlplus. Is this possible? if yes just give me an example for doing that. (2 Replies)
Discussion started by: boopathyvasagam
2 Replies

8. Shell Programming and Scripting

production issue - shell sqlplus processing sometime success sometime fail

Hi Expert, Below is a real production environment issue: we are using shell script to FTP to a remote server and fetch around 150 files every day, for each file we need to keep a entry inside ORACLE DB table, before insert into table, each file has a associated logid, which need to be... (2 Replies)
Discussion started by: summer_cherry
2 Replies

9. Shell Programming and Scripting

simple if/then issue in korn shell

When I run this, it tests to Y, but why? If I take the double quotes off of test, i get the same. # !/bin/ksh TEST="N" if ; then echo $TEST" yes" else echo "no" fi (4 Replies)
Discussion started by: guessingo
4 Replies

10. Shell Programming and Scripting

calling sqlplus from shell

Hi All, I am executing the following code :- sqlplus -s ${DATABASE_USER} |& print -p -- 'set feed off pause off pages 0 head off veri off line 500' print -p -- 'set term off time off serveroutput on size 1000000' print -p -- "set sqlprompt ''" print -p -- "SELECT run_command from... (2 Replies)
Discussion started by: suds19
2 Replies
Login or Register to Ask a Question