Skip to content

Shell script for running JCL jobs on the mainframe via ftp

IBA-mainframe-dev edited this page Nov 16, 2020 · 1 revision

Shell script for running JCL jobs on the mainframe via ftp

runZosJcl.sh script is intended to execute job from z/OS dataset via ftp

Also, this Shell script template can be used as part of the Jenkins pipeline to automate the launch of JCL jobs.

Link to shell script sources (runZosJcl.sh)

Instructions:

Execution format::

>./runZosJcl.sh [job] [output_file]
  • job - fully-qualified job name in quotation marks
  • output_file - file where job output log will be saved

Script returns 1 if dataset with JCL was not found or job failed (completed with error or RC>04)

Example:

>./runZosJcl.sh 'USER01.TESTPROG.JCL(TEST)' build_output.txt

runZosJcl.sh

#!/bin/sh
HOST=#Mainframe IP-address here#
USERID=#MF User#
USERPSW=#User password#

echo reading input parameters
INPUTJOB=$1
OUTPUT=$2
echo JCL: $INPUTJOB
echo Output file: $OUTPUT

TMPFILE=tmp.txt

echo run JCL from z/OS
echo "
open ${HOST}
quote USER ${USERID}
quote PASS ${USERPSW}
quote SITE FILE=JES NOJESGETBYDSN
quote SITE JESOWNER=*
quote site jesjobname=*
get '$INPUTJOB' $OUTPUT
bye
" | ftp -nv > $TMPFILE

echo ---------------
cat $TMPFILE
echo ---------------

JOB_ID=$( grep -o "JOB[0-9][0-9]*" $TMPFILE | head -1 )
if [ -z "$JOB_ID" ]
then
   echo Error: job was not submitted
   exit 1
else
   echo Job $JOB_ID was submitted
fi
sleep 5s

echo check rc code
echo "
open ${HOST}
quote USER ${USERID}
quote PASS ${USERPSW}
quote site file=jes
quote site jesjobname=*
ls
bye
" | ftp -nv > $TMPFILE

#echo ---------------
#cat $TMPFILE
#echo ---------------

grep $JOB_ID $TMPFILE
RC_CODE=$(grep $JOB_ID $TMPFILE | grep -o "RC=[0-9]*")
if [ -n "$RC_CODE" ]
then
        RC_CODE=$(echo "$RC_CODE" | cut -d "=" -f 2)
fi
if [ -n "$RC_CODE" ] && [ "$RC_CODE" \< "0008" ]
then
        echo Job completed successfully
else
        echo Error: job failed
        res="failed"
fi
rm $TMPFILE

if [ "$res" = "failed" ]
then exit 1
fi

z/OS System operating

SMP/E

Mainframe automation solutions and best practices

z/OS DevOps scripts

RACF

REXX scripts

ISPF

HSM

Useful tricks

Batch jobs (JCLs)

z/OS System operating

z/OS Subsystem operating

Clone this wiki locally