Execute script on Linux from Mainframe using REXEC

Sunday, September 14, 2014

Execute script on Linux from Mainframe using REXEC

REXEC runs commands on remote computers running the Rexec service (daemon). The rexec command authenticates the user name on the remote computer before executing the specified command.

Here we will see how to execute a script(.sh) residing on a Linux machine from a Mainframe job (JCL). I have also created a custom error handling module (COBOL) which will read the output log from script to see if the script execution was successful. In our shop we had to implement this to do bulk data extract from SYBASE database using a script and to FTP the data to mainframe dataset for further processing.

Step 1:- Create script and copy the same to your Linux machine directory

Sample Script(.sh) to display system date

#  Script Name   : displayDate.sh
#  Created By     : Entechlog, Sep 2014
# Move system date and hostname to a variable
TODAY=$(date)
HOST=$(hostname)

# Display date\time and system name
echo "-----------------------------------------------------"
echo "Date: $TODAY                     Host:$HOST"
echo "-----------------------------------------------------"

# Return code of shell script for mainframe error handling
echo "Return code of shell script is: " $?

Step 2:- Compile below error handle module.

REXECRCD(Remote Execute Return Code) Handle COBOL module

Step 3:- Create JCL to execute the script in Linux machine.

REXEC and REXECRCD JCL

Update below fields in JCL before running the job and add your job card.

JOBLIB      - Job lib for error handle module
scriptdir       - Location of script in Linux server
userid          - User ID for Linux server
password    - Password for Linux server
servername  - Remote server address

Step 4:- JEM and Run the JCL

If the script execution is successful on remote machine then the sys print dataset of REXEC step should look like








As REXEC step will always have a RC of 00 unless there is some connection issue, to make sure the script on remote system ran fine we have the mandatory return code validation step(REXERCD) which reads the output(SYSPRINT) from REXEC step and gives user abend incase if there was issue with script execution.

Below is the sample output from REXECRCD step



Error 404

The page you were looking for, could not be found. You may have typed the address incorrectly or you may have used an outdated link.

Go to Homepage