ksh command substitution not executing block commands


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ksh command substitution not executing block commands
# 1  
Old 04-14-2011
ksh command substitution not executing block commands

We have a function defined in a ksh script that gets called repeatedly and concurrently by background jobs called from within the same shell script file to run PL/SQL commands against an Oracle database. The function is below:

Code:
 
runPLSQL()
{
   ORACLE_SID=${1}
   procName=${2}
   
   # Set up proper Oracle environment #
   unset ORAENV_ASK
   ORAENV_ASK=NO
   . oraenv
   
   # Now execute the PL/SQL code #
   VALUE=`sqlplus -s ${ORACLE_USERNAME_PASSWORD} <<_EOF_
   whenever oserror exit failure
   whenever sqlerror exit sql.sqlcode
   set heading off
   set recsep off
   set feedback off
   set pagesize 0
   set linesize 100
   set trimspool on
   set serverout on size 1000000
   exec ${procName}
   quit
_EOF_`
 
}

This works 99% of the time, but every once in a while it does not execute the steps within the block:
whenever oserror exit failure
whenever sqlerror exit sql.sqlcode
set heading off
set recsep off
set feedback off
set pagesize 0
set linesize 100
set trimspool on
set serverout on size 1000000
exec ${procName}
quit
Using set -x in the script reveals the following output on the 1% occasion:

+ sqlplus -s /
+ 0<< \_EOF_
_EOF_

So, it shows that none of the hard coded commands between the first line and the last line of the block are sent to sqlplus.

In the 99% case, the following is the output from set -x

+ sqlplus -s /
+ 0<< \_EOF_
whenever oserror exit failure
whenever sqlerror exit sql.sqlcode
set heading off
set recsep off
set feedback off
set pagesize 0
set linesize 100
set trimspool on
set serverout on size 1000000
<plsql call was here>
quit
_EOF_


Has anyone ever seen this behavior before? We are running Red Hat Enterprise Linux Server release 5.3 (Tikanga)
# 2  
Old 04-14-2011
Quote:
Originally Posted by rjgst5
Has anyone ever seen this behavior before?
It won't print the here-document until the program actually reads it. Try this:

Code:
# echo ignores stdin
echo <<EOF
a
b
c
d
EOF
# cat does not
cat <<EOF
q
w
e
r
t
y
EOF

So it's not the shell that's ignoring the here-document, just sqlplus...

Check $? after you run sqlplus there to see what its return code is, that might help find a clue why.
# 3  
Old 04-14-2011
Maybe /tmp was full at the time?
# 4  
Old 04-15-2011
Quote:
Originally Posted by Corona688
It won't print the here-document until the program actually reads it. Try this:

Code:
# echo ignores stdin
echo <<EOF
a
b
c
d
EOF
# cat does not
cat <<EOF
q
w
e
r
t
y
EOF

So it's not the shell that's ignoring the here-document, just sqlplus...

Check $? after you run sqlplus there to see what its return code is, that might help find a clue why.

I added the check on $? after the sqlplus and it returned zero.

+ sqlplus -s /
+ 0<< \_EOF_
_EOF_
+ VALUE=''
+ sqlplusRtnCd=0

I changed the sqlplus whenever to be as follows as well but it still returned zero.

whenever oserror exit 100
whenever sqlerror exit 200

I will check on the /tmp space issue when it runs tomorrow. Thanks.
# 5  
Old 04-15-2011
Quote:
We have a function defined in a ksh script that gets called repeatedly and concurrently
Exactly how does the recursion process work and at what frequency. What username (other than "root") is executing the recursive process.

Why ask this?
It is quite easy to exceed your configured kernel limits with a recursive process.
# 6  
Old 04-15-2011
It is a non-root user and it is not really recursion as it is not calling itself. The runPLSQL function is being called by another function (function1 for example) in a loop lower in the same script file in the background.

That loop keeps up to 50 calls to function1 running concurrently using background tasks and function1 calls runPLSQL 3 times for each execution.
# 7  
Old 04-15-2011
Time to look at the maximum number of processes allowed by a non-root user in your kernel. You appear to be describing these symptoms but have evaded the question.
Maybe try:
Code:
ps -fuwhateveruser | wc -l

and compare with the kernel configuration for the maximum number of processes allowed per user.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Vi quick substitution commands

I have a script that has quite a lot of these types of entries: hello=$(who am i) good=$(blahblah) what i want to do is replace the $( and the ) with `` so that they look like this: hello=`who am i` good=`blahblah` I tried this: :%s~=$(&&)$~=`&&`$~g (3 Replies)
Discussion started by: SkySmart
3 Replies

2. Shell Programming and Scripting

Using Sed to do a substitution inside ksh

I'm trying to do an ls from inside of a ksh script. I loop through the results one line at a time and attempt to do a substitution using sed to convert YYYYMMDD from the older files into the newer files. Basically sometimes the ETL load runs over midnight and half the files are off by one day... (3 Replies)
Discussion started by: Calbrenar
3 Replies

3. Shell Programming and Scripting

Using commands inside sed substitution

Dear Friends, Please let me know how to use the date command inside the substitution flag replacement string. echo "01 Jan 2003:11:00:06 +0100" | sed 's/\(.*\)/`date -d \1 "+%Y%m%d%H%M%S"`/' I want to supply \1 string to Here mention below as part of replacement string, date -d <Here>... (5 Replies)
Discussion started by: tamil.pamaran
5 Replies

4. Shell Programming and Scripting

bad substitution error in ksh

Hello, In bash I can use the following: TMP=12345 MID=${TMP:1:1} the expected result is: 2 but when using KSH I'm getting a ''bad substitution" error. What is the correct syntaxin ksh? Thanks (2 Replies)
Discussion started by: LiorAmitai
2 Replies

5. Shell Programming and Scripting

bad substitution error in ksh

hi, i created a shell script having the following content: #! /usr/bin/ksh FROM="myemail@domain.com" MAILTO="someemail@domain" SUBJECT="TEST" BODY="/export/home/adshocker/body.txt" ATTACH="/export/home/adshocker/attach.prog" echo $ATTACH ATTACH_NAME="${ATTACH##*/}" echo $ATTACH_NAME... (5 Replies)
Discussion started by: adshocker
5 Replies

6. Shell Programming and Scripting

variable substitution in ksh

Hi I have a variable BIT1 which holds some value. Is there a way to retrieve the value of this variable indirectly via another variable, lets say SUBSET_BIT_NUM=1, so the call will look something like this: sundev1 $ echo ${BIT${SUBSET_BIT_NUM}} ksh: ${BIT${SUBSET_BIT_NUM}}: bad substitution ... (3 Replies)
Discussion started by: aoussenko
3 Replies

7. Solaris

Substitution not working in ksh

Hi, Following code is working in bash but not in ksh. Can someone please send me an alternative? #!/bin/ksh fname="EOA.dmp" echo $fname logname=${fname/.dmp/.log} echo $logname I am getting below error in ksh "testcmd: logname=${fname/.dmp/.log}: 0403-011 The specified substitution... (3 Replies)
Discussion started by: arsheshadri
3 Replies

8. AIX

Substitution not working in ksh

Following code is working in bash but not in ksh. Can someone please send me an alternative? #!/bin/ksh fname="EOA.dmp" echo $fname logname=${fname/.dmp/.log} echo $logname I am getting below error in ksh "testcmd: logname=${fname/.dmp/.log}: 0403-011 The specified substitution is not... (2 Replies)
Discussion started by: arsheshadri
2 Replies

9. Shell Programming and Scripting

KSH variable substitution

Hi folks Please let me know if anyone knows how to handle this. My KSH script -> testscript.ksh cmd=$1 ENV="devl" echo $cmd This is how I call the script ./testscript.ksh 'ps -ef | grep br$ENV' How do I get this to print the below text i.e $ENV should be substituted with the value... (5 Replies)
Discussion started by: tipsy
5 Replies

10. Shell Programming and Scripting

ksh substitution

Hello, I thought it was possible to use several time a #! entry on a script but it doesn't seems to work. My need is to have a part of a ksh script without substitution so it would look like #!/bin/ksh -- first part --- #!/bin/ksh -f -- part without substitution -- #!/bin/ksh --... (2 Replies)
Discussion started by: solea
2 Replies
Login or Register to Ask a Question