None

System commands from Microfocus JCLs


How to run linux sytem commands from JCL in Microfocus Enterprise Server.

By Kostas Koutsogiannopoulos

There are many cases on batch jobs running emulated z/OS utilities, cobol programs etc that we need to run a Linux system command or a bash script as one or more steps of the job. In order to do that we need a cobol program that runs the command and gets the exit code.

An example of such a program is bellow:

 CALLSYS.COM

       IDENTIFICATION DIVISION.
       PROGRAM-ID. CALLSYS.
       AUTHOR.     EPILIS.
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 WORK-COMMAND.
           03 COMMAND         PIC X(80)  VALUE SPACES.
           03 FILLER          PIC X(002) VALUE X"00".
       01 COM-COUNTER         PIC 99     VALUE ZEROES.
       01 WORK-COMMAND-LENGTH PIC 99     VALUE ZEROES.
       01 WS-COUNT            PIC 99     VALUE ZEROES.                
       PROCEDURE DIVISION.
           MOVE ZEROES TO RETURN-CODE
           PERFORM UNTIL COM-COUNTER > 98
           ADD 1 TO COM-COUNTER
           ACCEPT COMMAND
           INSPECT FUNCTION REVERSE(COMMAND)
            TALLYING WS-COUNT FOR LEADING SPACE
           COMPUTE WORK-COMMAND-LENGTH = LENGTH OF WORK-COMMAND -
           WS-COUNT
           IF COMMAND > SPACE THEN
            DISPLAY "Executing command (" COM-COUNTER "): " COMMAND
            CALL 'SYSTEM' USING WORK-COMMAND(1:WORK-COMMAND-LENGTH)
            DISPLAY "Return code is: " RETURN-CODE
             IF RETURN-CODE > 0 THEN
                DISPLAY "----------------------"
                DISPLAY "PROBLEM WITH COMMAND: " COMMAND
                DISPLAY "Aborting!!!"
                MOVE 16 TO RETURN-CODE
                GOBACK
             ELSE
                DISPLAY  WORK-COMMAND(1:WORK-COMMAND-LENGTH) "....OK"
             END-IF
            MOVE SPACES TO COMMAND
            MOVE ZEROES TO WORK-COMMAND-LENGTH
            MOVE ZEROES TO WS-COUNT
           ELSE GOBACK
           END-IF
           END-PERFORM
           GOBACK.

 

This program reads one by one the lines from sysin and runs them as linux system commands getting the exit code.
If RC > 0, the program exits with RC = 16. So a sample JCL that is using "CALLSYS.COB" to run two system commands is the following:

//EPILIS JOB
//CALLSYS1 EXEC PGM=CALLSYS
//SYSIN    DD *
ls -l
/home/admin/backup.sh

SYSOUT

Executing command (01): ls -l
Return code is: 00000
ls -l  ....OK
Executing command (02): backup.sh
Return code is: 32512
----------------------
PROBLEM WITH COMMAND: backup.sh
Aborting!!!


View epilis's profile on LinkedIn Visit us on facebook X epilis rss feed: Latest articles