This is possible, you can use the dbaccess or a 3rd party application (SQLCMD for example).
With dbaccess , if you want to use the user password , must create the SQL into a file and execute this file with dbaccess,
if you try execute in another way will get error -32412:
/tmp> echo " connect to \"db@myserver\" user dummy using ymmud" | dbaccess
32412: USING clause unsupported. DB-Access will prompt you for a password.
Error in line 1
/tmp> finderr 32412
-32412 USING clause unsupported. DB-Access will prompt you for a password.
DB-Access does not support the USING password clause in a CONNECT ...
USER statement when it violates security. For example, do not type a
password on the screen where it can be seen or include it in a command
file that someone other than the user can read. To maintain security,
DB-Access prompts you to enter the password on the screen and uses echo
suppression to hide it from view.
connect to \"$DB@$DB_INSTANCE\" user $USR using $PWD ;
execute procedure SP_PRECAL_ALERT_EXPIRY('12') ;
" > /tmp/sql.tmp.$$
dbaccess - /tmp/sql.tmp.$$ >/dev/null 2>&1
## to debug the SQL
## dbaccess -e - /tmp/sql.tmp.$$
rm -f /tmp/sql.tmp.$$ >/dev/null 2>&1
About how trap erros, if you are use BASH or KSH Shell , you can use the $? variable, if $? differ 0 (zero) a error occur.
echo execute procedure test_proc() | dbaccess sysmaster
if [ $? -ne 0 ]; then
echo "error occur!"
## to more information about $? execute on your UNIX: man ksh OR man bash
## to more information about "[ -ne ]" execute on your UNIX: man test