1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Restart parameter

Discussion in 'Linux and Unix' started by grinder182533, Feb 21, 2011.

Thread Status:
Not open for further replies.
  1. grinder182533

    grinder182533 Thread Starter

    Jun 1, 2009
    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.
  2. lotuseclat79


    Sep 12, 2003
    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
As Seen On
As Seen On...

Welcome to Tech Support Guy!

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.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/981948