#
# Template driver script for background job
#

debug=Y                     # to support testing

AppId=report                # AppId is short description of application
Ltmp=/tmp                   # Work/Log area for the app, publicly writeable
UseLock=Y                   # Y to use lockfiles, N not to

[ $UseLock = Y ] && LOCKFILE=$Ltmp/$AppId.LOCK  # Name of lockfile

echo                        # Announce the nature of the application
echo (Name of report)
echo

if [ $UseLock = Y -a -f $LOCKFILE ]; then       # check for lock file
    echo "\nSorry, a related report is running. Please try again later."
    exit 1
fi

if [ $UseLock = Y ]; then                       # Prevent zombie lock file if
    trap "rm $LOCKFILE; exit 1" 1 2 3 9 14 15   #   user interrupts this script
    touch $LOCKFILE                             # Create the lockfile
fi

if [ $debug = Y ]
then                                    # If debugging, create output file 
    outlog=$AppId.out                   # in the current directory  
else
    outlog=/Ltmp/$AppId.log             # else create in the standard place
fi

bgrun.sh $outlog <<END
#   *** insert command here ***
    [ $UseLock = Y ] && rm $LOCKFILE
END

# alternate form, if a script file has been created as $script:
# bgrun.sh $outlog <$script

echo "This process is now running in the background."

# Give user additional information about output here, if anything to tell.
