Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2007
    Posts
    2

    Post Unanswered: Pass variable from Sybase to shell

    Community,

    I know how to do this in oracle , but cant deduce the way out in sybase.
    I need to pass out the variable from sybase sql anonymous block into shell , so that
    I can play with the variable value in shell.

    Help me out ....

  2. #2
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    Sorry, I don't understand, can you give an example?

  3. #3
    Join Date
    Jun 2007
    Posts
    2

    Clarification

    Will give you a brief idea----
    from shell I enter the sybase T-sql,
    run a normal sql
    based on some criteria from the sql result i populate a variable in sybase.

    Now I need to pass this variable to shell so that I can perform neccesary actions.

  4. #4
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    You'll have to output the result to a file
    then read the file
    e.g. Here is a script that will return the last day of the month for any date passed as an argument
    Code:
    #!/bin/ksh
    #export PS4='$LINENO: '
    #set -xv
    indate=${@-$(date '+%Y%m%d')} 
    sn=$(basename "$0")
    logfile=/tmp/"$sn".log$$
    trap 'rm "$logfile"' 0
    isql -Usa -P -Smysrv -b -o$logfile <<EOF 
    set nocount on
    select convert(char(11),dateadd(dd,-1,dateadd(mm,datediff(mm,'1900-01-01','$indate')+1,'1900-01-01')),106)
    go
    EOF
    grep "Msg" "$logfile" >/dev/null 
    if [ $? -ne 1 ]
    then 
      cat "$logfile"
      exit 12
    fi
    eom=$(cat "$logfile")
    echo "Last day of the month is: $eom"
    Last edited by pdreyer; 06-25-07 at 07:35.

Posting Permissions

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