An excellent series by IBM on writing scripts that intelligently handle errors and alerts.
http://www.ibm.com/developerworks/aix/library/au-satbuildscript.html