Restartibility Functionality....

Hello,
I am trying to write a script that has a option of restarting the script from where it failed. I have to write a script called Batch.sh. This script has to run quite a few sql files as shown below:

logcmd.sh -f test1.sql
logcmd.sh -f test2.sql
logcmd.sh -f test3.sql
logcmd.sh -f test4.sql
...............................
..............................
logcmd.sh -f test50.sql

If the script fails let say at test3.sql and we rerun this script, it should start the process from test3.sh and onwards. It should NOT run test1.sh and test2.sh again. If there are no error in the previous run and we run the script again it should start from the beginning i.e. test1.sh.

I will really appreciate if anyone has sample of script that I can take a look or any advice to acheive this scenario.

Any help will be appreciated.

Thanks

A simple way would be to use case statments. Use your test#.sql
as arguments to your main script. Make sure any scripts that follow
are part of the case statement being called. This is for sh and bash
shells other shells may be slightly different.

"$var" in
value1)
commands;
;;
value2)
commands;
;;

esac

ex.

main.test.sql test2.sql

This would cause your main script to accept test2.sql as the value for
$1, or 1st argument to main.test.sql and the main script would start at
the 2nd case value.

case "$1" in
'test1.sql')
<dir path>/test1.sql
<dir path>/test2.sql #so on and so forth
<dir path>/test3.sql
;;
'test2.sql')
<dir path>/test2.sql
<dir path>/test3.sql
#continue this pattern untill all following test have been included
;;

esac

I recently wrote a script to install software releases that needed to be restartable. There are lots of steps, so I didn't want to have to repeat code (even though most is in separate functions) so it uses a pointer to the current step and compares this with an optional restart point provided as a run-time parameter. The bare bones are:

Code

# Set up defaults
restartpoint=0
step=0

# parse run time parameters
while getopts :d:l:r:s:uh OPTION ...
do
  case $OPTION in
...
  s) restartpoint=$OPTARG;;
...
     exit 0;
  esac
done

while :
do
  if [ $restartpoint -le $step ]; then
    case $step in
    0) {
	Code for step zero
       };;
    1) {
	Code for step 1
       };;
... code for rest of steps here ...
    *) break;;
    esac
  else
    print "Step $step skipped"
  fi
  step=$(($step + 1))
done
... cleanup code here

I wanted to control restarts automatically, but you could automate the restart by writing the last successfully completed step to a file and read this at the start of the script to work out the restart point.

Does this help?

You could also consider modifying your scripts to write "endpoints" to a file that tracks what has been successfuly completed. Then apply thestevew's good idea to read the file and have your script figure out where to start.

I think this a good idea to write the broken sql filename to a file. I will try to write a script and see if this works.

Thanks a bunch for the suggestions.

Raj