# SccsId[] = "%W% (USL function) %G%"
              TRX_name="TRAP_EXIT"
              if [ ".${SECONDS}" = "." ]; then # Bourne function already loaded?
                 [ ."`set|egrep '^$TRX_name\(\)\{$'`" != . ] && TRX_loaded=1
              else # Korn or Bash shell and function already loaded?
                 if [ `expr "\`uname -s\`" : "[Ll][Ii][Nn][Uu][Xx]"` -eq 0 ]; then
                    [ ."`typeset +f|awk '/^'$TRX_name'[=\(]?/'`" != . ] && TRX_loaded=1
                 else # Linux
                    [ ."`typeset -F|awk '/^'$TRX_name'[=\(]?/'`" != . ] && TRX_loaded=1
                 fi
              fi
              if [ 0${TRX_loaded} -eq 0 ]; then
              #----------------------------------------------------------------------#
              TRAP_EXIT() # Function documentation located at bottom.                #
              #----------------------------------------------------------------------#
              {
                if [ .${SHLIB} = . ]; then SHLIB=/usr/local/scripts; export SHLIB; fi

                . $SHLIB/email_msg.sh            # Function dependencies
                . $SHLIB/write_err_to_syslogs.sh

                #------------------------------------------------------------#
                # If the following variables are not set, use these defaults.#
                #------------------------------------------------------------#
                : ${script_name:=`basename $0`}
                : ${sp:="                    "}

                TRX_ID="$script_name($TRX_name)"

                #------------------------------------------------------------------#
                # An argument is assumed to be the interrupt that sprang the trap. #
                #------------------------------------------------------------------#
                if [ $# -gt 0 ]; then
                   TRX_intr="(intr=$1)"
                   shift
                else
                   TRX_intr="(intr=?)"
                fi

                TRX_m1="ABEND $TRX_ID $TRX_intr"
                TRX_m3="'$@' terminated"
                EMAIL_MSG "$TRX_m1" \
                  "${sp}$TRX_m2"
                if [ ."$TERM" = . ]; then # Not running interactively.
                   WRITE_ERR_TO_SYSLOGS $syslog_emergency "ABEND: $TRX_m1 $TRX_m2 $TRX_m2"
                fi
                EXIT 1
              } # "TRX_" prefix identifies this function's variables
              fi

              #======================================================================#
              #                       D O C U M E N T A T I O N                      #
              #======================================================================#
              #                                                                      #
              #      Author: Bob Orlando                                             #
              #                                                                      #
              #        Date: December 14, 1996                                       #
              #                                                                      #
              #  Program ID: trap_exit.sh                                            #
              #                                                                      #
              #       Usage: TRAP_EXIT <no options|arguments>                        #
              #                                                                      #
              #     Purpose: Gracefully exit on trapped signal.                      #
              #                                                                      #
              #     Globals: No global variables are assigned in this function.      #
              #              "TRX_" prefix identifies local function variables.      #
              #                                                                      #
              # Exit_status: Exits with failure (1).                                 #
              #                                                                      #
              #       Calls: EMAIL_MSG and EXIT library functions.                   #
              #                                                                      #
              #       Notes: .....................................................   #
              #              .....................................................   #
              #                                                                      #
              #    Modified: 2004-04-02 Bob Orlando                                  #
              #                 v1.9  * Expand $AWK testing and assignment.          #
              #                                                                      #
              #              2004-03-03 Bob Orlando                                  #
              #                 v1.8  * Change set|egrep|awk to just set|egrep.      #
              #                                                                      #
              #----------------------------------------------------------------------#
            
Artificial Intelligence is no match for natural stupidity.
©Copyright Bob Orlando, 1996-2011
All rights reserved.
http://www.OrlandoKuntao.com
E-mail: Bob@OrlandoKuntao.com
Last update: Jan. 26, 2011
by Bob Orlando