Help req for...shell script to catch "db2 connect" errors ...

Hello friends,

Assume that, I am trying to execute a "db2 connect" command from Linux shell prompt via a shell script called "sample"

sample
db2 connect to bas39

$sample

If the database is not present its should display a custom error message by catching the error message given by db2. how to do this using shell script ?.

Probably it will help me to convert error codes to much more meaningful message......help me. thanks. :confused:

Inside sample, put this:

#!/bin/sh
db2 connect to bas39 2>/tmp/db_error$$
exit_code=$?

while read line ; do
    echo "$line" | grep -q "SOMEERROR" && echo "You got some error there, buster" && continue
    echo "$line" | grep -q "OTHERERR" && echo "Oh not another one!" && continue
    echo "$line" | grep -q "still another error" && echo "Geez this database stinks!" && continue
    # Add as many echo/grep/continues as you need...
done < /tmp/db_error$$
exit $exit_code