I have an error handling function that traps, reports and exits on an error.
My problem is that I want to do all of that and I want to still see stdout.

Can anyone help with this? Here is the function. If I change sources.list to
have an invalid source it reports, but I do not see the progress when there
is no error.

#!/bin/bash
logfile=/root/upgrade.log

        # R1040 error handling
        function run()
        {
            CMD=$1
                echo 
            # Don't abort on errors
            set +e
            # Capture STDERR to ERR
            ERR=$($CMD 2>&1)
            # Capture return value from command
            RETVAL=$?
            # re-enable abort-on-errors
            set -e

            return $RETVAL
        }

        function errhandler()
        {
                echo "********** ERROR DETECTED in $CMD **********" | tee -a
$logfile
                echo "********** Error reported was \"$ERR\"" | tee -a
$logfile
                echo "Exiting script abnormally. The error above was
reported in log at $logfile"
                exit 1
        }

        trap errhandler ERR
        run 'apt-get update'
        # should not get past this on error
        echo "no"


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to