Eugene F wrote:
A regular OS shell has no facility to communicate with database except
for the return code from DB2 CLP that only flags success of its
execution (0) or failure (not 0). For your task perl would be a better
choice.
-Eugene
Or Python or Ruby :-)
(though, as I understand it, Perl is the only one with an "official"
feature-replete driver from IBM; Ruby and Python basically have "bare
essentials" community efforts which, frankly, need quite a bit more
work)
One other quick point: if you do go the shell script route, the failure
exit codes from the CLP aren't quite standard:
0=success
1=a fetch returned no rows (not an error)
2=statement warning (not an error)
4=statement error
8=CLP error
Check the Reference / Commands / DB2 Universal Database / Command Line
Processor (CLP) / CLP return codes section in the Info Center for more
information. So, you'll want to do something like:
#!/bin/bash
db2 -x CONNECT TO $db >/dev/null
if [[ $? -ge 4 ]]; then
echo "Failed to connect to $db"
exit 1
fi
value=$(db2 -x SELECT somefield FROM sometable)
if [[ $? -ge 4 ]]; then
echo "Failed to run query"
exit 1
fi
HTH,
Dave.
--