Capturing output of procedure in variable in shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Capturing output of procedure in variable in shell script
# 1  
Old 12-13-2010
Capturing output of procedure in variable in shell script

Hi guys
I am calling one DB2 stored proc through unix. It is giving me below output. I want to capture the value 150 in one UNIX variable in shell script. Please let me know how I can achieve this. Thanks in advance

Value of output parameters
--------------------------
Parameter Name : ROW_CNT
Parameter Value : 150
Return Status = 0
# 2  
Old 12-13-2010
Please show how u r executing DB2 stored procedure in your shell script. Also, do u redirect the output of this procedure to any file?
R0H0N
# 3  
Old 12-13-2010
I am doing like below...

a=call DWH.P_CALC_COUNT('TABLE_NAME',?)

when I am doing echo $a

it is giving below output :

Value of output parameters -------------------------- Parameter Name : ROW_CNT Parameter Value : 100 Return Status = 0

I want to just capture 100 here and store it in some variable.

Kindly let me know if you have any solution.
# 4  
Old 12-14-2010
It would be better if u spool the output of this procedure into a file and then grep the value of parameter from that spooled file. Hope u understand what I have pointed out.

DB Procedure:
Code:
spool abc.txt
your procedure content
spool off

Shell script:
Code:
call DWH.P_CALC_COUNT('TABLE_NAME',?) 
a=`grep "Parameter Value" abc.txt | sed 'g/ /d' | cut -d":" -f2`

And if u r not allowed to do so, then execute following sed command to extract parameter value.

Code:
a=`call DWH.P_CALC_COUNT('TABLE_NAME',?)  | sed 's/Parameter Value : (.*) Return Status/\1/g'`

R0H0N
# 5  
Old 12-14-2010
Code:
a=$(call DWH.P_CALC_COUNT('TABLE_NAME',?) |awk '/ Parameter Value/ {print $NF}' )

# 6  
Old 12-14-2010
Code:
{ read; read; read; read line; val=${line##* } ;} << EOV
$a
EOV

Code:
val=${a##*Value : }
val=${val%%
*}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[SOLVED] Capturing output in a korn variable

Hi, I'm new to korn and having trouble capturing the text output from one program in an array that I can then feed into another program. Direct approaches didn't work, so I've tried to break it down thus: The program lonlat2pixline gives the values I need in the second column, so I print that... (4 Replies)
Discussion started by: daurin
4 Replies

2. 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

3. Shell Programming and Scripting

Capturing Sybase SP output in Shell Script

Greetings, I need to capture the output of a Sybase stored procedure, inside my shell script( k shell). Based on this output, I need to call another perl script, with input arguments as the result set of the procedure execution. I need to keep looping through and call the perl script, ... (2 Replies)
Discussion started by: rajpreetsidhu
2 Replies

4. Shell Programming and Scripting

Losing new lines when capturing output to variable

Explain this? $ ls | grep -e "crd\|cs" crd cs $ CLONES=`ls | grep -e "crd\|cs"`;echo $CLONES; crd cs $ CLONES=`ls | grep -e "crd\|cs"`;echo "$CLONES"; crd cs (1 Reply)
Discussion started by: blasto333
1 Replies

5. Shell Programming and Scripting

Bourne Shell: Clean Display of stored procedure's output

Environment: Sun UNIX Language: Bourne Shell I have the following script and it works fine. Unfortunately, from user's perspective, it looks very messy because the user is able to see the output of the process caused by the print command. Is there a better way to overcome it? Here's the... (10 Replies)
Discussion started by: totziens
10 Replies

6. Shell Programming and Scripting

Capturing shell script command output

I am trying to check to see if a file exists on a ftp server, well, I know that cant be done, atleast directly, So I came up with this small script ftp -n $HOST <<END_SCRIPT quote USER $USER quote PASS $PASSWD cd public_html/crap dir $FILE quit END_SCRIPT Where the $ variable... (2 Replies)
Discussion started by: designflaw
2 Replies

7. 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

8. Shell Programming and Scripting

capturing output in script

I have the following line in my script: $sftpcmd $rmthost <<COMMANDS>> $sftplog 2>&1 For some reason this is not capturing the errors from sftp, they go to the file attached to the cron entry ie mm hh dd MM * /myscript > cron.out any idea why? digital unix 4.0d (6 Replies)
Discussion started by: MizzGail
6 Replies

9. UNIX for Dummies Questions & Answers

capturing the output of grep as integer variable

Hi, I have an expression using grep and nawk that captures the ID number of a given Unix process. It gets printed to screen but I don't know how to declare a variable to this returned value! For example, ps -ef|grep $project | grep -v grep | nawk '{print $2}' This returns my number. How... (2 Replies)
Discussion started by: babariba
2 Replies

10. UNIX for Dummies Questions & Answers

capturing oracle procedure out param value

I have a procedure with an out parameter, I want to use this value in a shell script, I've done this in perl before but they want this to be a ksh script. what is the syntax to do this. this was my first thought; #!/usr/bin/ksh sqlplus -s scott/tiger@db << EOF ... (1 Reply)
Discussion started by: edog
1 Replies
Login or Register to Ask a Question