guess you should include the following at the beginning of your scripts ... if I have correctly understood your pb ;)

WHENEVER OSERROR exit;
WHENEVER SQLERROR exit;