How to check for background processes error code
===

I have the following shell script which I test each command individually to see if they fail or not. I want to agilize the processing of the files by sending all the runDP.sh to the background and if one of they fail I want the whole script to be interrupted.

I have seen many options of doing the error trapping, but couldn't find any that would suit my needs. I need a clean output of the script and nothing to be popping out all the time.

I need a clear:

Processing File ABC
ABC File completed

or if it fails:

ABC File processing failed -- Error X

Here is my current script:


for file in *_$1_$BATCH_NAME_*1.dat
do

    echo "`date +%Y-%m-%d\ %H:%M:%S` - Processing File: $DIS_FILE ..."
    $INGESTION_HOME/scripts/runDP.sh $DIS_FILE 2> /dev/null 
    if [ $? -ne 0 ]
    then
       echo "  Error pre-processing: $DIS_FILE ..."
       exit 1
    fi
    $INGESTION_HOME/scripts/runDL.sh $DIS_FILE 2> /dev/null
    if [ $? -ne 0 ]
    then
       echo "  Error loading: $DIS_FILE ..."
       exit 1
    fi
done
