# Restart Utility in Unix

**URL:** <https://techcommunity.softwareag.com/t/restart-utility-in-unix/180814>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-on-Linux\
**Created:** [February 27, 2015, 6:23am UTC](https://techcommunity.softwareag.com/t/restart-utility-in-unix/180814 "2015-02-27T06:23:51Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vasanth\_Murali](https://avatars.discourse-cdn.com/v4/letter/v/ce73a5/32.png) [@Vasanth\_Murali](https://techcommunity.softwareag.com/u/Vasanth_Murali)\
**Post date:** [February 27, 2015, 6:23am UTC](https://techcommunity.softwareag.com/t/restart-utility-in-unix/180814/1 "2015-02-27T06:23:51Z")

</div>

Hi All,

Our project uses Natural/ ADABAS in UNIX. So instead of JCL we use Scripts.

So whenever we want to submit a script (JCL) from a particular step, we either delete the steps above or comment them manually. ( In Mainframe JCL, we have restart=stepname)

So is there a way to use or create the restart utility in UNIX?

Note - This is how we submit out scripts

/home/userid\> SCRIPTNAME env ( env is either dev, uat or prod) environments)

Let me know if you did or have something similar in your project.

Regards,  
Vasanth

Regards,  
Vasanth

---

<div class="post-metadata">

**Author:** ![Giles](https://avatars.discourse-cdn.com/v4/letter/g/c68b51/32.png) [@Giles](https://techcommunity.softwareag.com/u/Giles)\
**Post date:** [February 27, 2015, 10:23am UTC](https://techcommunity.softwareag.com/t/restart-utility-in-unix/180814/2 "2015-02-27T10:23:12Z")

</div>

There is no equivalent to restart. Deleting/commenting out is the only way (AFAIK).

---

<div class="post-metadata">

**Author:** ![Todd\_Beckwith](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/todd_beckwith/32/388_2.png) [@Todd\_Beckwith](https://techcommunity.softwareag.com/u/Todd_Beckwith)\
**Post date:** [February 27, 2015, 1:59pm UTC](https://techcommunity.softwareag.com/t/restart-utility-in-unix/180814/3 "2015-02-27T13:59:46Z")

</div>

I don’t know of an elegant way to tell script to simply GOTO a certain line. If you divide your script into functions, you could simulate restart functionality to some degree. Unfortunately this wouldn’t be as easy as adding a RESTART parameter. If interested in looking into using functions as a solution, osvaldomarques posted an example in the thread linked below.

[url][http://www.linuxquestions.org/questions/programming-9/bash-goto-384407/[/url]](http://www.linuxquestions.org/questions/programming-9/bash-goto-384407/%5B/url%5D)

HTH

---

<div class="post-metadata">

**Author:** ![Ralph\_Zbrog](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/ralph_zbrog/32/78_2.png) [@Ralph\_Zbrog](https://techcommunity.softwareag.com/u/Ralph_Zbrog)\
**Post date:** [February 27, 2015, 10:13pm UTC](https://techcommunity.softwareag.com/t/restart-utility-in-unix/180814/4 "2015-02-27T22:13:58Z")

</div>

A colleague came up with this and has used it in a few scripts - those really needing restartability.

When restarting, you provide the starting step via a parameter, in this example, parm 1.

```auto
RESTART=$1
RESTART=${RESTART:=000}

STEP=010
if [$STEP -ge $RESTART]
then
  echo this is step $STEP
fi

STEP=020
if [$STEP -ge $RESTART]
then
  echo this is step $STEP
fi
```

---

<div class="post-metadata">

**Author:** ![Vasanth\_Murali](https://avatars.discourse-cdn.com/v4/letter/v/ce73a5/32.png) [@Vasanth\_Murali](https://techcommunity.softwareag.com/u/Vasanth_Murali)\
**Post date:** [March 3, 2015, 7:05am UTC](https://techcommunity.softwareag.com/t/restart-utility-in-unix/180814/5 "2015-03-03T07:05:31Z")

</div>

Thanks Ralph,

I am still unclear about the solution. Where can we pass the parm? In the jobcard or while submitting the script?

The below is the Job card. In the $1, we store the environment (dev,uat,prd) while submitting the script.

```auto

#!/bin/bash
# ----------------------------------------------------
# usage :
# JOB DESCRIPTION:    
# ----------------------------------------------------
rc=0
max_rc=0
env=$1;export env

if [$# -ne 1]
then
  echo `date` "job $0 $$ Usage"
  echo "environment should be specified" $# "- job stopped"
  exit 4
fi

# ----------------------------------------------------
# set environment parameters 
# ----------------------------------------------------
. ./setup_dev2
echo "$jobname $pid `date` started" >> $MSGLOG
```

The code works when the step name are in regular pattern ( Ascending?) ?

It would be very helpful if you could provide me a working example, for my easy understanding.

Regards,  
Vasanth

---

<div class="post-metadata">

**Author:** ![Matthias1](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@Matthias1](https://techcommunity.softwareag.com/u/Matthias1)\
**Post date:** [March 3, 2015, 10:34am UTC](https://techcommunity.softwareag.com/t/restart-utility-in-unix/180814/6 "2015-03-03T10:34:59Z")

</div>

Hi Vasanth Murali,

First of all: I don’t know much about JCL-Logic. But I’m sure you can write some logic using a shell script. For example you can use a simple textfile to control single steps of a Job.

Here’s a first draft.

Content of the textfile is for example:

```auto
01 PROG1
02 PROG2
03 PROG3
04 PROG4
```

the script processing the textfile is:

```auto
rm -f textfile.temp
do_exit=0
cat textfile.txt | while read step prog result
do 
  echo STEP:$step
  echo PROG:$prog
  echo RESULT:$result
  if [$do_exit = "1"]
  then
    # skip steps due to error before
    echo $step $prog $result >> textfile.temp
  else
    if ["$result" = "0"] # already done sucessfully
      then
      echo $step $prog $result >> textfile.temp
    else
      if ["$result" = ""] # not done yet
      then
        echo "starting $prog now..."
        # starting prog here
        returncode=$?
      else # restart due to error
        echo "restarting $prog due to result $result now..."
        # restart prog here
        returncode=$?
      fi
      echo $step $prog $returncode>> textfile.temp
      if [$returncode -ne 0] # some error
      then
        echo "$prog failed with $returncode. Exiting now ..."
        do_exit=1
      fi
    fi
  fi
done
mv textfile.temp textfile.txt
exit $returncode
```

HTH

---

<div class="post-metadata">

**Author:** ![Vasanth\_Murali](https://avatars.discourse-cdn.com/v4/letter/v/ce73a5/32.png) [@Vasanth\_Murali](https://techcommunity.softwareag.com/u/Vasanth_Murali)\
**Post date:** [March 3, 2015, 2:00pm UTC](https://techcommunity.softwareag.com/t/restart-utility-in-unix/180814/7 "2015-03-03T14:00:34Z")

</div>

Thanks Matthias,

Let me explain the JCL stuff and what I really want.

Below is the code

```auto

#!/bin/bash
rc=0
max_rc=0
env=$1;export env

if [$# -ne 1]
then
  echo `date` "job $0 $$ Usage"
  echo "environment should be specified" $# "- job stopped"
  exit 4
fi

# ----------------------------------------------------
# set environment parameters 
# ----------------------------------------------------
. ./setup_dev2
echo "$jobname $pid `date` started" >> $MSGLOG

# ---------------------------------------------------
# Lock multiple jobs
# ---------------------------------------------------
while [-f $workdir/lockfile_$jobname]
do
  sleep 10
done
touch $workdir/lockfile_$jobname
echo "$jobname $pid `date` locked" >> $MSGLOG
# ===================================================================
# STEP: RF005P
# JOB DESCRIPTION:
# AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
# LAST DATE CHANGED - 01/31/03
# ===================================================================
# -------------------------------------------------------------------
# -------------------------------------------------------------------
STEP=AAAAAAA; export STEP

NATPGM=AAAAAA; export NATPGM
CMPRT01=${dir}/AAAA.AA1.AAA05P.prt; export CMPRT01
CMPRT02=${dir}/AAA02.AAA005P.prt; export CMPRT02
CMPRT03=${dir}/AAA05P03.AA005P.prt; export CMPRT03
CMPRT04=${dir}/AAA05P04.AA005P.prt; export CMPRT04
${proclib}/NATQBTCH

# check return code
rc=$?
rc_AAAA=$rc
echo `date` "JOB $jobname step AAAAA completed rc=$rc" >> $MSGLOG
echo `date` "JOB $jobname step AAAAA completed rc=$rc"  
. ${proclib}/max_rc.sh noterm
 
unset CMPRT01 CMPRT02 CMPRT03 CMPRT04 NATPGM STEP 
 
# -------------------------------------------------------------------
# STEP: BBBBBB ( in original JCL: COND=(0,NE) )
# BBBBBBBBBBBBBBBBBBBBBBBBBBBB
# -------------------------------------------------------------------
 STEP=BBBBB; export STEP
 if ["$rc" -eq "0"] 
 then

 NATPGM=BBBBBB; export NATPGM
 CMPRT01=${dir}/BBBBB.BBBB01.BBBB.prt; export CMPRT01
 ${proclib}/NATTEST

 check return code
 rc=$?
 rc_BBBBBB=$rc
 echo `date` "JOB $jobname step BBBBBB completed rc=$rc" >> $MSGLOG
 echo `date` "JOB $jobname step BBBBBB completed rc=$rc"  
 . ${proclib}/max_rc.sh noterm
 
 unset CMPRT01 NATPGM STEP 
 else
  echo `date` "JOB $jobname step $STEP not run because COND code rc=$rc" >> $MSGLOG
  echo `date` "JOB $jobname step $STEP not run because COND code rc=$rc" 
 fi 
 
#----------------------------------------------------
# release multiple jobs
# ---------------------------------------------------
echo $jobname $pid `date` completed >> $MSGLOG
if [-f $workdir/lockfile_$jobname]
then
rm $workdir/lockfile_$jobname
fi

# ---------------
# end of job
# ---------------
exit $max_rc
```

so in the above script ( JCL), we have two steps AAAAAAA and BBBBBB ( I just took 2 steps for ease of understanding. We have 10, 20 or sometimes more steps in a script).

So if I want to run from BBBBB, I delete or comment the AAAAAA step. So instead I want to use an utility which will allow me to run from BBBBBB.

Something like if I give RESTART = BBBBBB, it should skip the steps before BBBBBB .

Let me know if you still have any questions and your code does the same?

Regards,  
Vasanth

---

<div class="post-metadata">

**Author:** ![Ralph\_Zbrog](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/ralph_zbrog/32/78_2.png) [@Ralph\_Zbrog](https://techcommunity.softwareag.com/u/Ralph_Zbrog)\
**Post date:** [March 4, 2015, 10:58pm UTC](https://techcommunity.softwareag.com/t/restart-utility-in-unix/180814/8 "2015-03-04T22:58:20Z")

</div>

There is no such functionality built-in to Unix. Unless your job scheduling package has it, you must build it yourself by modifying your scripts.

If your script were called JCL01, you would enter the following command in a shell:

```auto
sh -x JCL01.bsh Dev
```

To restart at the second step, you would enter:

```auto
sh -x JCL01.bsh Dev BBBBB
```

I’ve modified the logic to allow alphanumeric step names, and their ascending sequence is no longer required. My changes are marked with “# \<\<\<”.

```auto
    #!/bin/bash  
    rc=0  
    max_rc=0  
    env=$1;export env  
    RESTART=$2 # <<<
    if ["x${RESTART}" = "x"] # <<<
    then # <<<
      EXEC-ALL=TRUE # <<<
    else # <<<
      EXEC-ALL=FALSE # <<<
    fi # <<<

    if [$# -ne 1]  
    then  
      echo `date` "job $0 $$ Usage"  
      echo "environment should be specified" $# "- job stopped"  
      exit 4  
    fi  
      
    # ----------------------------------------------------  
    # set environment parameters   
    # ----------------------------------------------------  
    . ./setup_dev2  
    echo "$jobname $pid `date` started" >> $MSGLOG  
      
    # ---------------------------------------------------  
    # Lock multiple jobs  
    # ---------------------------------------------------  
    while [-f $workdir/lockfile_$jobname]  
    do  
      sleep 10  
    done  
    touch $workdir/lockfile_$jobname  
    echo "$jobname $pid `date` locked" >> $MSGLOG  
    # ===================================================================  
    # STEP: RF005P  
    # JOB DESCRIPTION:  
    # AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA  
    # LAST DATE CHANGED - 01/31/03  
    # ===================================================================  
    # -------------------------------------------------------------------  
    # -------------------------------------------------------------------  
    STEP=AAAAAAA; export STEP  
    if [${EXEC-ALL} = "TRUE"] || ["x${STEP}" = "x${RESTART}"] # <<<
    then # <<<
      EXEC-ALL=TRUE # <<<
                                                                     # <<<
    NATPGM=AAAAAA; export NATPGM  
    CMPRT01=${dir}/AAAA.AA1.AAA05P.prt; export CMPRT01  
    CMPRT02=${dir}/AAA02.AAA005P.prt; export CMPRT02  
    CMPRT03=${dir}/AAA05P03.AA005P.prt; export CMPRT03  
    CMPRT04=${dir}/AAA05P04.AA005P.prt; export CMPRT04  
    ${proclib}/NATQBTCH  
      
    # check return code  
    rc=$?  
    rc_AAAA=$rc  
    echo `date` "JOB $jobname step AAAAA completed rc=$rc" >> $MSGLOG  
    echo `date` "JOB $jobname step AAAAA completed rc=$rc"    
    . ${proclib}/max_rc.sh noterm  
      
    unset CMPRT01 CMPRT02 CMPRT03 CMPRT04 NATPGM STEP   
    fi # <<<
      
    # -------------------------------------------------------------------  
    # STEP: BBBBBB ( in original JCL: COND=(0,NE) )  
    # BBBBBBBBBBBBBBBBBBBBBBBBBBBB  
    # -------------------------------------------------------------------  
    STEP=BBBBB; export STEP  
    if [${EXEC-ALL} = "TRUE"] || ["x${STEP}" = "x${RESTART}"] # <<<
    then # <<<
      EXEC-ALL=TRUE # <<<
                                                                     # <<<
    if ["$rc" -eq "0"]   
    then  
      
    NATPGM=BBBBBB; export NATPGM  
    CMPRT01=${dir}/BBBBB.BBBB01.BBBB.prt; export CMPRT01  
    ${proclib}/NATTEST  
      
    check return code  
    rc=$?  
    rc_BBBBBB=$rc  
    echo `date` "JOB $jobname step BBBBBB completed rc=$rc" >> $MSGLOG  
    echo `date` "JOB $jobname step BBBBBB completed rc=$rc"    
    . ${proclib}/max_rc.sh noterm  
      
    unset CMPRT01 NATPGM STEP   
    else  
      echo `date` "JOB $jobname step $STEP not run because COND code rc=$rc" >> $MSGLOG  
      echo `date` "JOB $jobname step $STEP not run because COND code rc=$rc"   
    fi

    fi # <<<
      
    #----------------------------------------------------  
    # release multiple jobs  
    # ---------------------------------------------------  
    echo $jobname $pid `date` completed >> $MSGLOG  
    if [-f $workdir/lockfile_$jobname]  
    then  
    rm $workdir/lockfile_$jobname  
    fi  
      
    # ---------------  
    # end of job  
    # ---------------  
    exit $max_rc  
```

Further questions should posted to a Unix forum.

---

<div class="post-metadata">

**Author:** ![Vasanth\_Murali](https://avatars.discourse-cdn.com/v4/letter/v/ce73a5/32.png) [@Vasanth\_Murali](https://techcommunity.softwareag.com/u/Vasanth_Murali)\
**Post date:** [March 11, 2015, 4:02am UTC](https://techcommunity.softwareag.com/t/restart-utility-in-unix/180814/9 "2015-03-11T04:02:57Z")

</div>

Thanks Ralph,

Your code gives me some idea. I will see if I can develop it further.

Regards,  
Vasanth

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [April 2, 2021, 3:32pm UTC](https://techcommunity.softwareag.com/t/restart-utility-in-unix/180814/10 "2021-04-02T15:32:58Z")

</div>


