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 ?
db2 load from ....
if [ $? != 0 ]; then
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.