Controling a statement to execute

Hi All
I have a script which runs a piece of JOB. The jobs are in sequence and if it fails at a particular job I wanted it to be started from the point where it failed.

What I did I prepared two properties file one which contains the entire List of the JOBS which are to be executed and the other in which I maintain the jobs which are successfully executed.

Before executing these jobs I check if its already executed and if so then I Skip the step.

The property file is having entry like
EODJOB=6000
EODJOB=6001
EODJOB=6002
.......

The script is as follows
#############################################

#! /usr/bin/ksh
# A test to automate the whole EOD

echo "Starting FX Front Office EOD..."

brn_num=$1
set -e on
echo "Running FX Front Office EOD for Branch Number: $brn_num "
echo "Running FX Front Office EOD for Branch Number: $brn_num" > error.txt 2>&1

rootdir=$PWD
fullpropfile=$rootdir/FULL_FX_EOD_JOB.properties
completedpropfile=$rootdir/COMPLETED_FX_EOD_JOB.properties

if [  `grep -c "^EODJOB=" $fullpropfile` -gt 0 ]
    then
    echo "Running the EOD Process"
    for i in `grep "^EODJOB=" $fullpropfile | cut -f2 -d"="`
    do
        
        if [  `grep -c "^EODJOB="$i $completedpropfile` -gt 0 ]
            then 
            echo $i Job is already executed for branch =$brn_num and hence skipping the job..........
        else
            echo executing the job $i for branch=$brn_num
            . ./runEod.sh $i $brn_num>> error.txt 2>&1
                if [ $# -eq 0 ]   #ok execution
                    then
                    echo $i Process completed for Branch No:=$brn_num
                    echo writing into job into completed list 
                    echo 'EODJOB='$i>>COMPLETED_FX_EOD_JOB.properties
                fi
        fi

    done
echo "FX Front Office EOD for Branch Number: $brn_num run successfully"
fi
echo erasing the completed job list
echo "">$completedpropfile
###############################################

The problem is that I am clering the file which contains the completed job entry at the last.
And say if a job fails it goes and clear the file.

What i need is that only if the entire file is sucessfully executed then only I should clear the file and if the scripts fails in between it should skip this step.

Kindly suggest any way

Note: This is not AIX specific, should have been posted in the Shell Scripting subboard; recall this next time please :slight_smile:

I am not sure how you check if your job was ok or not - I guess you will have to parse your error.txt... ?
So just react to this and not simply erase your file in the end, wether it was succesful or not, as you do it atm.
Not sure if your runEod.sh produces an exit code you can use to decide what to do next.
Since you have this script and probably wrote it yourself, I guess you can easily adjust to your efforts?

Many thanks for your inputs.
The reason i posted here in AIX was because the server is IBM AIX and hence i posted here. Will take care of the point you mentioned as it makes easier to manage things if placed in correct path.

However I think there is a way in shell scripting by which say if a script fails at a particular point then in that case it stops execution there itself and does not proceed further. How to achieve that?

Ok, no problem :slight_smile:

Not that I know of...
Error handling is usually done via Exit/Return Codes and checking them with if/fi and additionally using break/continue to steer through the logic of the script, if needed.

For example if commands in your script are executed, check the value of $? and if it is not zero, usually something has gone wrong.

While in this section of code:

if [ $# -eq 0 ]   #ok execution

could you add:

ok_exec="Y"

then, at the end, do the following:

if [ $ok_exec = "Y" ]
   then
   echo erasing the completed job list
   echo "">$completedpropfile
fi

Probably you might want to read the ksh documentation about "traps". It seems to me that this is doing exactly what you want.

I hope this helps.

bakunin