If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Capturing Stored Proc O/P in Shell Script

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-19-09, 08:22
Raj85 Raj85 is offline
Registered User
 
Join Date: Aug 2009
Posts: 4
Capturing Stored Proc O/P in Shell Script

Greetings,

I have a shell script (ksh), which needs to run sybase quieries. Based on the o/p,
I need to call another perl program. I am not sure, how do I capture the output of the
sybase query, as it would be split into number of rows(not fixed, based on WHERE clause)
I was just working on a sample script. It looks like-

#!/bin/ksh
. /usr/local/ccms/pgl/cfg/pgl.env
echo ${SERVER} ${USER}
VAR=`isql -S${SERVER} -U${USER} -P${PASSWD} <<ENDOFTEXT
set nocount on
set rowcount 5
select UserId as 'Id' from tempdb..test_user
go
quit
ENDOFTEXT `
echo $VAR
#echo "values "
#echo $VAR | awk -F" " '{print $2}'
#col_look="this is test"

IFS=' '
set -A bar $VAR
echo ${#VAR[@]}
echo ${bar[0]}
echo ${bar[1]}
echo ${bar[2]}
echo ${bar[3]}
echo "I am finished "

For example, the query returns,
id
---
1
2
3
4
5

I need to use each of these values i.e. 1,2,3 etc as an input parameter to another program.
Hence, need to capture them into variables.
As no. of rows(hence these variables) is not fixed, also,
the o./p is in different rows, I am finding it difficult to capture them.

Appreciate your help.
Reply With Quote
  #2 (permalink)  
Old 08-19-09, 10:53
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,455
Cool Piece of cake

If you need to use all variables as parameter to one process, just do this:
Code:
#!/bin/ksh
. /usr/local/ccms/pgl/cfg/pgl.env
echo ${SERVER} ${USER}
VAR=`isql -S${SERVER} -U${USER} -P${PASSWD} <<ENDOFTEXT
set nocount on
set rowcount 5
select UserId as 'Id' from tempdb..test_user
go
quit
ENDOFTEXT `
echo $VAR
IFS=' '
set -A bar "$VAR"
#
# Exec other script like this:
other_script.sh $VAR
#
# -- or this -- 
other_script.sh $bar 
#
__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
  #3 (permalink)  
Old 08-19-09, 12:00
Raj85 Raj85 is offline
Registered User
 
Join Date: Aug 2009
Posts: 4
Re:Capturing Stored ProcO/P in Shell Script

thanks for the reply...But I need to call the other_script.pl, using each of the O/P values.
Say 1,2,3,4,5 are the Ids returned.
I need to call it 5 times
as
other_script.pl 1
--do smthng
other_script.pl 2
--do smthng
other_script.pl 3
--do smthng
other_script.pl 4
--do smthng
other_script.pl 5
--do smthng

Appreciate your help.
Reply With Quote
  #4 (permalink)  
Old 08-19-09, 13:29
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,455
ok, then...

OK, then try something like this:
Code:
#!/bin/ksh
. /usr/local/ccms/pgl/cfg/pgl.env
echo ${SERVER} ${USER}
VAR=`isql -S${SERVER} -U${USER} -P${PASSWD} <<ENDOFTEXT
set nocount on
set rowcount 5
select UserId as 'Id' from tempdb..test_user
go
quit
ENDOFTEXT `
echo $VAR
#
# Exec other script like this:
for p in $VAR
do
  other_script.sh $p
done

PS: You do not need an array.
__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
  #5 (permalink)  
Old 08-19-09, 23:11
Raj85 Raj85 is offline
Registered User
 
Join Date: Aug 2009
Posts: 4
Worked well :-)

hey Thanks a lot for the help.It worked well ..
Appreciate your response..
Reply With Quote
  #6 (permalink)  
Old 08-20-09, 07:56
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,455
Cool Ok!

Ok, no problemo.
__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On