Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2009
    Posts
    4

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

  2. #2
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    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

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

  4. #4
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    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

  5. #5
    Join Date
    Aug 2009
    Posts
    4

    Worked well :-)

    hey Thanks a lot for the help.It worked well ..
    Appreciate your response..

  6. #6
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Cool Ok!

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •