Catching errors

Hi,

I'm writing a scheduling script which will co-ordinate the launching of scripts.
This script is scheduling based on an input file, and launches the appropriate scripts at the right times.

The only issue I'm having is:

  • if a script dies, or even has a syntax error, I want to catch that.
  • this is needed as the scheduler script will have to put a hold on that script until it is fixed.

Here's what I have:

...
if [ "${beforeRunScript}" == "TRUE" ]; then
    if [ -f "${additionalScriptsPath}/before_${workerScript}.sh" ]; then
        echo "  ********************************"
        echo "  * START: \"Before Run\" script *"
        echo "  ********************************"
        $ . "${additionalScriptsPath}/before_${workerScript}.sh"
        errorCode=$?
        if [ ! "${errorCode}" == "0" ]; then
            echo `addToErrorQueue "${processName}" "${workerScript}" "${errorCode}" "Before-Run script has failed. A hold has been put on the process until it is fixed."`
            keepGoing=FALSE
        fi
        echo "  *******************************"
        echo "  * DONE: \"Before Run\" script *"
        echo "  *******************************"
    fi
fi
...

beforeRunScript is just a flag deciding whether or not the file is needed.
additionalScriptsPath is just the path where the script to be executed resides.
workerScript is just part of the name of the script to be launched.

When I run this code, I get:

...
********************************
* START: "Before Run" script *
********************************
./chk_master_script.sh[465]: $:  not found
*******************************
* DONE: "Before Run" script *
*******************************
...

If I run this code without the $ prior to the . (dot), when calling the script, the code works fine, but if errors exist in the called script, they're not caught by this scheduler script.

Also, the script being run must have access to all variables in this scheduler script, that's why I'm calling the script with the . (dot).

Any help would be great.

Just a small addition;
I'm currently writing the stderr to a file and reading that file into a variable.

This works, but I'd like to skip the whole file.
Is there a way to route standard error to a variable rather than a file?

This is what I now have:

...
. "${additionalScriptsPath}/before_${workerScript}.sh" 2> ${workingPath}/junk
errorCode=`cat "${workingPath}/junk"`
...