Restartibility Functionality....


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Restartibility Functionality....
# 1  
Old 04-27-2006
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
rkumar28
# 2  
Old 04-27-2006
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
# 3  
Old 04-28-2006
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:
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?
# 4  
Old 04-28-2006
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.
# 5  
Old 04-28-2006
Restartibility Functionality....

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
rkumar28
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Zip -r Functionality

Hi , I've written the following code to zip the big file $dir_temp ="/home/etc/hst zip -r $dir_temp/file_nm.zip $dir_temp/file_nm The zip file has been created . When I try to UNZIP the file with the following command unzip file_nm.zip The file got unzipped but created in the... (3 Replies)
Discussion started by: smile689
3 Replies

2. Shell Programming and Scripting

Adding the email functionality

I have make an menu in which first option is to start and second is to stop the services echo "Please enter the appropriate choice for doing the operations" echo " 1) STOP Services 2) START Services case $choice in 1) ... (4 Replies)
Discussion started by: punpun66
4 Replies

3. UNIX for Dummies Questions & Answers

Command Functionality

Hi everyone, today i need that someone help to understand this particular line of command. So you can explain to me step by step, it will be great. ---------- Post updated at 11:53 AM ---------- Previous update was at 11:51 AM ---------- (9 Replies)
Discussion started by: Newer
9 Replies

4. Shell Programming and Scripting

using arrays and also help with array.contains functionality

here is what i have... i=1 while read line do if grep -i-q "create procedure"<<<$line then startline="$line" endline="blahblah" Get procedure name into a variable named procName procName="procedure name is stored" do some... (2 Replies)
Discussion started by: vivek d r
2 Replies

5. UNIX for Dummies Questions & Answers

Help with the functionality of the last (&/or who) command.

I'm a Bash Newbie, hope you guys can help. n.n Ok, So I need to make a script that will get a list of the Users that are/have logged in (recently). I've been wondering how to get it with either the last or the who command. This Poses a problem, as with who, it ONLY shows the Users... (3 Replies)
Discussion started by: lsteamer
3 Replies

6. Shell Programming and Scripting

Pipe Functionality

Hi, I am trying to emulate the '|' functionality through pipe function call. I am passing the o/p of exec in parent as input to the exec in child. The buf is readin the o/p but the exec in child is not working. Can somebody checkout the code and point where am i going wrong or missing something.... (3 Replies)
Discussion started by: amejoish
3 Replies

7. Shell Programming and Scripting

Vlookup functionality in Bash

Hi please help in the below request Input File 1: a,1 b,2 c,3 d,4 e,5 f,6 Input File 2: 2 5 3 1 Output Required: b 2 e 5 c 3 (3 Replies)
Discussion started by: ravin
3 Replies

8. UNIX for Dummies Questions & Answers

using functionality in another ksh

i have a function defined in one ksh i want to use the same functionality in another ksh i am using . ../<ksh name> but it is not picking that functionality what i have to do for the same (2 Replies)
Discussion started by: trichyselva
2 Replies

9. Shell Programming and Scripting

Sed functionality

I have a few xml files and I want to input say 5 parameters within each file. is it possible to do so with sed? <parameter>A</parameter> <parameter>B</parameter> .... .... And so on. These parameters are meant to go in just inside: <?xml... (2 Replies)
Discussion started by: collern2
2 Replies

10. UNIX for Dummies Questions & Answers

Date functionality

Hi, Could someone help me to get yesterday's date in MMDDYY format. echo `date '+%m%d%y'` is giving me today's date in the above format. Thanks in advance for your help.. Suresh. (1 Reply)
Discussion started by: svannala1
1 Replies
Login or Register to Ask a Question