I wrote a script to capture some rows from the DB.
However I want to capture the errors if the DB instance is down which usually produces errors like below. What should be my approach to kill script if the DB instance is down:
DATABASE ERRORS:
Msg 937, Level 14, State 1:
Server 'UAT_SRVR10':
Database 'test2' is unavailable. It is undergoing LOAD DATABASE.
Msg 4001, Level 11, State 1:
Server 'UAT_SRVR10':
Cannot open default database 'test2'.
Msg 208, Level 16, State 1:
Server 'UAT_SRVR10', Line 1:
TST_TABLE not found. Specify owner.objectname or use sp_help to check whether
the object exists (sp_help may produce lots of output).
MY SCRIPT:
isql -U${dbuid} -P${dbpwd} -S${dbsrv} -w5000 << EOF >> outfile
select * from the testtable where testargs='zombie'
go
exit
EOF
if [[ $? != 0 ]]
then
echo "`date` Error has occured. Database is not available !! >>logfile
echo "`date` ABORTING ===================================" >>logfile
echo " kill my script if the above error generated !!!"
exit 11
fi
echo " DB connection met and continue to do the rest of the script"
System: SunOS 5.8 Generic_117350-53 sun4u sparc SUNW,Netra-T12
Database: Sybase