How do i restart a process if it fails?

Hi Guru's,

I just want to have an idea on how to restart a particular step when it fails?

SCENARIO
we have plenty of steps such as the following below:

Step 1
copy file from source to target location which is in a different server.

Step 2
create initial and incremental process

Step 3
Start initial extract from source location

and etc...

say step 3 fails, what i wanted to do is to just restart that step where it fails without restarting the whole process.

Any idea is much appreciated.

I think you can check/verify the status of step 3 and if the return status of step 3 is not successful you can re-run it along with counter re-run variable.

If you are crashing out of your code so you can fix the problem and you want to restart, you could pass in the step as an argument then each part of the main code can check if it is due to run or not. For example:-

$ cat step_restart_straight
#!/bin/ksh
# Just a quick step-restart demo

step="${1:-0}"

# Section 1
if [ $step -ge 1 ]
then
   echo "This is running Section 1."
fi

# Section 2
if [ $step -ge 2 ]
then
   echo "This is running Section 2."
fi

# Section 3
if [ $step -ge 3 ]
then
   echo "This is running Section 3."
fi

# Section 4
if [ $step -ge 4 ]
then
   echo "This is running Section 4."
fi
$ step_restart_straight
This is running Section 1.
This is running Section 2.
This is running Section 3.
This is running Section 4.
$
$ step_restart_straight 3
This is running Section 3.
This is running Section 4.
$

Another approach would be to use functions and have a loop round a case statement.

cat step_restart_functions
#!/bin/ksh
# Just a quick step-restart demo

function_one()
{
 echo "This is function 1"
}

function_two()
{
 echo "This is function $step."
}

function_three()
{
 echo "This is function $step."
}

function_four()
{
 echo "This is function 4"
}

step="${1:-0}"

while :
do
 case $step in
  0) : ;;                          # No action for zero step
  1) function_one ;;
  2) function_two ;;
  3) function_three ;;
  4) function_four ;;
  *) exit ;;
 esac

 ((step=$step +1))            # Increment count to go to next step
done                               # Go round and run next step
$ step_restart_functions  
This is function 1
This is function 2.
This is function 3.
This is function 4
$
$ step_restart_straight 3
This is function 3.
This is function 4
$

You can even use (as you can see) the value of the step within the function, so that may help /logging for messages or debug later.

I hope that this helps,
Robin
Liverpool/Blackburn
UK

You might want to adapt this: Multiple shell scripts executed in one script RudiC - Shell Programming and Scripting - Unix Linux Forums

Thanks a lot. :b: