There's no such thing as a stupid question, but they're the easiest to answer.


Search Search
Search for:
Tech Support Guy > > >

Restart parameter


grinder182533's Avatar
grinder182533 grinder182533 is offline
Member with 72 posts.
Join Date: Jun 2009
Experience: Intermediate
21-Feb-2011, 05:55 AM #1
Restart parameter
I have a shell script with 4 separate functions taking place, one after the other.
Is there a way to introduce a parameter so that if the job fails, then I can restart it at a specific point in the script ?
Ideally, the default will be null (or 1), so that it will not normally be set, and the script will start at the beginning.
But if the script were to fail between stages 2 and 3, say, then the script could be rerun, with the parameter set to 2.
lotuseclat79's Avatar
Member with 20,583 posts.
Join Date: Sep 2003
Location: -71.45091, 42.27841
21-Feb-2011, 11:12 AM #2
Hi grinder,

At the end of the script, put the following line:
exit 0
Construct your script based on a Case statement, where the default starting value is 0 on the value of the case variable, except if the exit code is 1, 2 or 3.
Make your script require one parameter where:
0 value means start from the beginning,
1 means start at the 2nd function (or case),

Test the exit value of the script, by issuing the command: echo $?
after the script has been run.

When you think about it, this script could be encased in another script, which loops based on the exit value and continue processing until an exit value of 0 is reached or it will loop infinitely (without user interaction.

Don't forget to put a -x at the end of the first line, i.e.: #!/bin/bash -x
in order to debug the script and see what lines are executing as you develop it.

-- Tom
The independence created by philosophical insight is - in my opinion - the mark of distinction
between a mere artisan or specialist and a real seeker after truth. - Einstein 1944
Imagination is more important than knowledge. - Einstein
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools

You Are Using: Server ID
Trusted Website Back to the Top ↑