Shell script for datasets transfering from UNIX to the mainframe via ftp - IBA-mainframe-dev/Global-Repository-for-Mainframe-Developers GitHub Wiki

Shell script for datasets transfering from UNIX to the mainframe via ftp

sendLIBS.sh was created to send source datasets to z/OS via ftp.

Link to shell script sources

Script configuration before execution

  1. Prepare file which contains list of datasets LLQ (HLQ should be specified in the shell script parameters at startup) to be sent to z/OS. Each dataset name is located in separate line, for example datasetsList file contains:
    TEST
    SAMPLIB
    JCL
    COBOL
    PLI
    ASM
    
    All libraries should be located in the current directory
  2. Replace the following values in the script:
  • HOST=#Mainframe IP-address here#
  • USERID=#MF User#
  • PASSWD=#User password#
  • DSQ='#Script default HLQ qualifiers#'

Sequence of script actions:

  • Script receives an input file with list of datasets, required for transfering
  • Sends datasets to z/OS

Execution format:

>./sendLIBS.sh [ds_list] [ds_qualifier] 
  • ds_qualifiers - HLQ and MLQ datasets on z/OS default: USER01.TEST

  • ds_list - file which contains list of datasets to be sent to z/OS each dataset name is located in separate line, for example: TEST ASM COBOL all libraries should be located in the current directory

Script returns 1 if at least one directory/file was not found or dir/file transfer was unsuccessful.

Execution examples:

>./sendLIBS.sh dsList USER01.TEST

sendLIBS.sh

#!/bin/sh
#echo reading input parameters
INPUTFILE=$1
DSQ=$2
echo Input jcl: $INPUTFILE
TMPFILE=tmp.txt

HOST=#Mainframe IP-address here#
USERID=#MF User#
PASSWD=#User password#
input="$PWD"

if [ ! -f "$INPUTFILE" ]
 then
  echo Error: Input file $INPUTFILE not found
  exit 1
fi

if [ -z "$DSQ" ]
 then
  echo use default qualifiers
  DSQ='USER01.TEST'
fi

echo datasets qualifiers: $DSQ

while read line
 do
    if [ -d "$input/$line" ]
    then
      PARAMS='LR=80 BLOCKSIZE=32720 REC=FB TR PRI=10 SEC=100 DIR=20'
      echo  copy "$line" lib to z/OS
      echo "
        open $HOST
        quote USER $USERID
        quote PASS $PASSWD
        quote site $PARAMS
        mkdir '$DSQ.$line'
        cd '$DSQ.$line'
        lcd $input/$line
        mput *
        ls
        bye
      " | ftp -inv > $TMPFILE
      echo ---------------
      cat $TMPFILE
      echo ---------------
    else
      if [ -f "$input/$line" ]
	 then
	    PARAMS='LR=80 BLOCKSIZE=32720 REC=FB TR PRI=5 SEC=100'
            echo  copy "$line" dataset to z/OS
            echo "
              open $HOST
              quote USER $USERID
              quote PASS $PASSWD
              quote site $PARAMS
              put $input/$line '$DSQ.$line'
              bye
            " | ftp -inv > $TMPFILE
            echo ---------------
            cat $TMPFILE
            echo ---------------
         else
            echo Error: $input/$line does not exist
	    res="error"
	    continue
      fi
    fi
    ERROR=$(grep -i 'Error' $TMPFILE)
    if [ -n "$ERROR" ]
     then
        echo Error occurred: $ERROR
        res="error"
    fi
done < $INPUTFILE

rm $TMPFILE

if [ "$res" = "error" ]
then
  echo Sending libs completed with errors 
  exit 1
fi

dsList file content example:

EXEC
INCLUDES
JCL
PLI
SAMPLIB
TEST