Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2003
    Posts
    84

    Unanswered: Shell script DB2 return code trapping for AIX (UDB V8.1)

    Can someone out there tell me how to check the return codes from a database operation and execute the next step conditionally from within a shell script ?
    e.g if I need to do a load and then execute another load after checking for successful completion of the first load how do I do it within a shell script ?

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1

    Re: Shell script DB2 return code trapping for AIX (UDB V8.1)

    It's the same as with any other OS command:

    Code:
    #!/bin/sh
    
    db2 load from ....
    if [ $? != 0 ]; then 
       echo "Error!"
       exit
    fi
    db2 load from ...
    You can find more details in Command Reference

  3. #3
    Join Date
    Jun 2002
    Location
    UK
    Posts
    525

    Re: Shell script DB2 return code trapping for AIX (UDB V8.1)

    It's the same as with any other OS command:

    Code:
    #!/bin/sh
    
    db2 load from ....
    if [ $? != 0 ]; then 
       echo "Error!"
       exit
    fi
    db2 load from ...
    You can find more details in Command Reference
    ... except that DB2 will return an exit status of 1 for warnings (e.g. updates where no rows found, loads/imports with warnings). For loads, these warnings may actually want to be treated as errors (particularly those which have involved data mutation). So the long and the short of it is that you are going to have to check the SQLSTATES returned in the stdout to determine if you have any warnings that should be treated as errors for your particular circumstances.

    At least that's what I've done in the past (using awk/grep). If you come up with a better solution, please post it.

    Damian

Posting Permissions

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