Restart Utility in Unix

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

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

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.

http://www.linuxquestions.org/questions/programming-9/bash-goto-384407/

HTH

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.

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

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.


#!/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

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:

01 PROG1
02 PROG2
03 PROG3
04 PROG4

the script processing the textfile is:

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

Thanks Matthias,

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

Below is the code


#!/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

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:

sh -x JCL01.bsh Dev

To restart at the second step, you would enter:

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 “# <<<”.

    #!/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.

Thanks Ralph,

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

Regards,
Vasanth