forked from richardschoen/QshOni
-
Notifications
You must be signed in to change notification settings - Fork 0
/
QSHEXECC.CLLE
324 lines (286 loc) · 15.8 KB
/
QSHEXECC.CLLE
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
PGM PARM(&CMDLINE &SETPKGPATH &DSPSTDOUT +
&LOGSTDOUT &PRTSTDOUT &DLTSTDOUT +
&IFSSTDOUT &IFSFILE &IFSOPT &CCSID +
&PRTSPLF &PRTUSRDTA &PRTTXT)
/*----------------------------------------------------------------------------*/
/* Variables */
/*----------------------------------------------------------------------------*/
DCL VAR(&SETPKGPATH) TYPE(*CHAR) LEN(4)
DCL VAR(&CMDLINE) TYPE(*CHAR) LEN(5000)
DCL VAR(&INPUTFILE) TYPE(*CHAR) LEN(255)
DCL VAR(&USERPW) TYPE(*CHAR) LEN(100)
DCL VAR(&OWNERPW) TYPE(*CHAR) LEN(100)
DCL VAR(&PDFOPTS) TYPE(*CHAR) LEN(8)
DCL VAR(&REPLACE) TYPE(*CHAR) LEN(4)
DCL VAR(&TEMPLATE) TYPE(*CHAR) LEN(255)
DCL VAR(&OUTPUTFILE) TYPE(*CHAR) LEN(255)
DCL VAR(&OUTPUTTYPE) TYPE(*CHAR) LEN(10)
DCL VAR(&PARMS) TYPE(*CHAR) LEN(2048)
DCL VAR(&PARMLIST) TYPE(*CHAR) LEN(1024)
DCL VAR(&PGMPARMS1) TYPE(*CHAR) LEN(256) VALUE(' ')
DCL VAR(&PGMPARMS2) TYPE(*CHAR) LEN(256) VALUE(' ')
DCL VAR(&PGMPARMS3) TYPE(*CHAR) LEN(256) VALUE(' ')
DCL VAR(&PGMPARMS4) TYPE(*CHAR) LEN(256) VALUE(' ')
DCL VAR(&TYPE) TYPE(*CHAR) LEN(1)
DCL VAR(&CURDIR) TYPE(*CHAR) LEN(128)
DCL VAR(&CDLEN) TYPE(*DEC) LEN(7 0)
DCL VAR(&OUTPUTDST) TYPE(*CHAR) LEN(10) VALUE('*NONE')
DCL VAR(&OUTPUTACT) TYPE(*CHAR) LEN(10) VALUE('*N')
DCL VAR(&QSHRTN) TYPE(*DEC) LEN(5 0)
DCL VAR(&QSHRTNC) TYPE(*CHAR) LEN(5)
DCL VAR(&MSGDTA) TYPE(*CHAR) LEN(200)
DCL VAR(&MSGDTA4) TYPE(*CHAR) LEN(4)
DCL VAR(&CPFID) TYPE(*CHAR) LEN(7)
DCL VAR(&CMD) TYPE(*CHAR) LEN(9999)
DCL VAR(&STDOUTIFS) TYPE(*CHAR) LEN(255)
DCL VAR(&STDOUTFILE) TYPE(*CHAR) LEN(255)
DCL VAR(&JOB) TYPE(*CHAR) LEN(10)
DCL VAR(&JOBNBR) TYPE(*CHAR) LEN(6)
DCL VAR(&USER) TYPE(*CHAR) LEN(10)
DCL VAR(&TEMPDIR) TYPE(*CHAR) LEN(255) +
VALUE('/tmp')
DCL VAR(&QSHTEMP) TYPE(*CHAR) LEN(255) +
VALUE('/tmp/qsh')
DCL VAR(&DSPSTDOUT) TYPE(*CHAR) LEN(4)
DCL VAR(&LOGSTDOUT) TYPE(*CHAR) LEN(4)
DCL VAR(&DLTSTDOUT) TYPE(*CHAR) LEN(4)
DCL VAR(&PRTSTDOUT) TYPE(*CHAR) LEN(4)
DCL VAR(&IFSSTDOUT) TYPE(*CHAR) LEN(4)
DCL VAR(&IFSOPT) TYPE(*CHAR) LEN(10)
DCL VAR(&IFSFILE) TYPE(*CHAR) LEN(255)
DCL VAR(&RTNVAL) TYPE(*CHAR) LEN(6)
DCL VAR(&CURJOB) TYPE(*CHAR) LEN(10)
DCL VAR(&CURUSER) TYPE(*CHAR) LEN(10)
DCL VAR(&CURNBR) TYPE(*CHAR) LEN(6)
DCL VAR(&QDATE) TYPE(*CHAR) LEN(6)
DCL VAR(&QTIME) TYPE(*CHAR) LEN(9)
DCL VAR(&PRTSPLF) TYPE(*CHAR) LEN(10)
DCL VAR(&PRTUSRDTA) TYPE(*CHAR) LEN(10)
DCL VAR(&PRTTXT) TYPE(*CHAR) LEN(30)
DCL VAR(&CCSID) TYPE(*CHAR) LEN(10)
/*----------------------------------------------------------------------------*/
/* MONITOR FOR GLOBAL ERROR. ANY ERROR IS A CAUSE TO BLOW OUT OF HERE */
/* AND WE WANT A GRACEFUL EXIT. */
/*----------------------------------------------------------------------------*/
MONMSG MSGID(CPF0000) EXEC(GOTO CMDLBL(ERRORS))
/*----------------------------------------------------------------------------*/
/* MAIN */
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
/* If copying results to IFS and IFS file is blank, bail out. */
/*----------------------------------------------------------------------------*/
IF COND(&IFSSTDOUT *EQ *YES) THEN(DO)
IF COND(&IFSFILE *EQ ' ') THEN(SNDPGMMSG +
MSGID(CPF9898) MSGF(QCPFMSG) +
MSGDTA('IFSSTDOUT was set to *YES, but no +
IFS file was specified. QSHEXEC +
cancelled') MSGTYPE(*ESCAPE))
ENDDO
/*----------------------------------------------------------------------------*/
/* Set environment path for QOpenSys packages if selected */
/* before running any PASE/QSH commands. */
/*----------------------------------------------------------------------------*/
IF COND(&SETPKGPATH *EQ '*YES') THEN(DO)
QSHPATH PKGPATH(*DEFAULT)
ENDDO
/*----------------------------------------------------------------------------*/
/* Create temp folder in /tmp named /tmp/qsh for stdout logs */
/*----------------------------------------------------------------------------*/
MKDIR DIR(&QSHTEMP) DTAAUT(*RWX) OBJAUT(*ALL)
MONMSG MSGID(CPF0000)
/*----------------------------------------------------------------------------*/
/* RETRIEVE JOB DATE/TIME INFO */
/*----------------------------------------------------------------------------*/
RTVSYSVAL SYSVAL(QDATE) RTNVAR(&QDATE)
RTVSYSVAL SYSVAL(QTIME) RTNVAR(&QTIME)
RTVJOBA JOB(&CURJOB) USER(&CURUSER) NBR(&CURNBR)
/*----------------------------------------------------------------------------*/
/* CREATE TEMPORARY OUTPUT FILE TO HOLD STDOUT RESULTS */
/*----------------------------------------------------------------------------*/
CRTPF FILE(QTEMP/STDOUTQSH) RCDLEN(1000) +
TEXT('QShell STDOUT Output') +
OPTION(*NOLIST *NOSRC) MAXMBRS(*NOMAX) +
SIZE(*NOMAX)
MONMSG MSGID(CPF0000)
/*----------------------------------------------------------------------------*/
/* CLEAR TEMPORARY QSH OUTPUT FILE */
/* BAIL OUT IF WE CANNOT CLEAR OUTPUT FILE */
/*----------------------------------------------------------------------------*/
CLRPFM FILE(QTEMP/STDOUTQSH)
/*----------------------------------------------------------------------------*/
/* BUILD PATH NAME FOR IFS STDOUT FILE */
/*----------------------------------------------------------------------------*/
RTVJOBA JOB(&JOB) USER(&USER) NBR(&JOBNBR)
CHGVAR VAR(&STDOUTIFS) VALUE(&QSHTEMP |< +
'/STDOUTQSH-' |< &JOB |< '-' |< &USER +
|< '-' |< &JOBNBR |< '-' |< &QDATE |< +
&QTIME |< '.TXT')
/*----------------------------------------------------------------------------*/
/* ERASE JAVA OUTPUT IF IT EXISTS */
/*----------------------------------------------------------------------------*/
ERASE OBJLNK(&STDOUTIFS)
MONMSG MSGID(CPF0000)
/*----------------------------------------------------------------------------*/
/* SET THE IFS PATH TO STORE QSHELL OUTPUT FOR */
/* REVIEW IF NEEDED. */
/*----------------------------------------------------------------------------*/
CHGVAR VAR(&STDOUTFILE) VALUE('FILE=' |< &STDOUTIFS)
/*----------------------------------------------------------------------------*/
/* SET THE QSHELL STDOUT IFS FILE LOCATION */
/* ENVIRONMENT VARIABLE */
/*----------------------------------------------------------------------------*/
ADDENVVAR ENVVAR('QIBM_QSH_CMD_OUTPUT') +
VALUE(&STDOUTFILE) REPLACE(*YES)
ADDENVVAR ENVVAR(QIBM_MULTI_THREADED) VALUE(Y) +
REPLACE(*YES)
/*----------------------------------------------------------------------------*/
/* Make sure iTookit CL commands will work when using the */
/* DB2 connectivity by setting job CCSID to 37 */
/*----------------------------------------------------------------------------*/
IF COND(&CCSID *NE *SAME) THEN(DO)
CHGJOB CCSID(&CCSID)
ENDDO
/*----------------------------------------------------------------------------*/
/* BUILD THE FINAL QSH CALL */
/*----------------------------------------------------------------------------*/
CHGVAR VAR(&CMD) VALUE(&CMDLINE)
/* CALL THE QSH COMMAND LINE */
QSH CMD(&CMDLINE)
/* READ AND PROCESS THE QSHELL RESPONSE */
/* TO DETERMINE QSH PROGRAM EXIT CODE */
NEXTCOMP: RCVMSG PGMQ(*SAME) MSGTYPE(*COMP) RMV(*NO) +
MSGDTA(&MSGDTA) MSGID(&CPFID)
/* IF MSGID IS BLANK, WE DIDN'T GET QSH0005 */
/* LIKE WE WERE SUPPSED TO. */
IF COND(&CPFID *EQ ' ') THEN(DO)
CHGVAR VAR(&QSHRTN) VALUE(9999)
CHGVAR VAR(&QSHRTNC) VALUE(&QSHRTN)
GOTO CMDLBL(DONECOMP) /* DONE WITH MSG LOOP */
ENDDO
/* QSH0005 IS THE RETURN RESPONSE FROM THE JAVA PGM */
IF COND(&CPFID *EQ 'QSH0005') THEN(DO)
CHGVAR VAR(&MSGDTA4) VALUE(%SST(&MSGDTA 1 4))
CHGVAR VAR(&QSHRTN) VALUE(%BIN(&MSGDTA4))
CHGVAR VAR(&QSHRTNC) VALUE(&QSHRTN)
GOTO CMDLBL(DONECOMP) /* DONE WITH MSG LOOP */
ENDDO
GOTO CMDLBL(NEXTCOMP) /* GET NEXT MSG UNTIL QSH */
DONECOMP:
/* COPY STDOUT TO QTEMP OUTFILE */
CPYFRMSTMF FROMSTMF(&STDOUTIFS) +
TOMBR('/QSYS.LIB/QTEMP.LIB/STDOUTQSH.FILE/STD+
OUTQSH.MBR') MBROPT(*REPLACE) CVTDTA(*AUTO) +
STMFCODPAG(*STMF) ENDLINFMT(*LF)
MONMSG MSGID(CPF0000) EXEC(DO)
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('Errors +
occurred while copying STDOUT log to +
file. Check the joblog') +
MSGTYPE(*ESCAPE)
ENDDO
/* If copying results to IFS, do it now */
/* We copy from STDOUTQSH in QTEMP to IFS log */
IF COND(&IFSSTDOUT *EQ *YES) THEN(DO)
CPYTOSTMF +
FROMMBR('/QSYS.LIB/QTEMP.LIB/STDOUTQSH.FILE+
/STDOUTQSH.MBR') TOSTMF(&IFSFILE) +
STMFOPT(&IFSOPT) CVTDTA(*AUTO) +
STMFCCSID(*PCASCII) ENDLINFMT(*LF) +
STMFCODPAG(*STMF)
/* Prevent endless loop if CPYTOSTMF fails */
MONMSG MSGID(CPF0000) EXEC(DO)
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('Error +
copying log to IFS file' |> &IFSFILE |> +
'- QSHEXEC cancelled') MSGTYPE(*ESCAPE)
ENDDO
ENDDO
/* IF ENABLED, PRINT STDOUT RESULTS */
IF COND(&PRTSTDOUT *EQ *YES) THEN(DO)
/* PRINT STDOUT LOG NOW */
OVRPRTF FILE(QSYSPRT) TOFILE(QSYSPRT) PAGESIZE(198) +
PRTTXT(&PRTTXT) HOLD(*YES) +
USRDTA(&PRTUSRDTA) SPLFNAME(&PRTSPLF)
CPYF FROMFILE(QTEMP/STDOUTQSH) TOFILE(QSYSPRT)
DLTOVR FILE(QSYSPRT)
ENDDO
/* IF ENABLED, DISPLAY STDOUT RESULTS */
IF COND(&DSPSTDOUT *EQ *YES) THEN(DO)
EDTF STMF(&STDOUTIFS)
MONMSG MSGID(CPF0000)
ENDDO
/* IF ENABLED, Erase stdout result file */
IF COND(&DLTSTDOUT *EQ *YES) THEN(DO)
ERASE OBJLNK(&STDOUTIFS)
MONMSG MSGID(CPF0000)
ENDDO
/* Write STDOUT results PF to job log */
IF COND(&LOGSTDOUT *EQ *YES) THEN(DO)
OVRDBF FILE(STDOUTQSH) TOFILE(QTEMP/STDOUTQSH)
CALL PGM(QSHSTDOUTR)
DLTOVR FILE(STDOUTQSH)
ENDDO
IF COND(&QSHRTN *NE 0) THEN(DO)
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('ERROR: +
QShell error' |> &QSHRTNC |> 'occurred +
while running command. Check +
the joblog') MSGTYPE(*ESCAPE)
ENDDO
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('QShell +
command completed') MSGTYPE(*COMP)
RETURN
ERRORS:
/* COPY STDOUT TO QTEMP OUTFILE */
CPYFRMSTMF FROMSTMF(&STDOUTIFS) +
TOMBR('/QSYS.LIB/QTEMP.LIB/STDOUTQSH.FILE/STD+
OUTQSH.MBR') MBROPT(*REPLACE) CVTDTA(*AUTO) +
STMFCODPAG(*STMF) ENDLINFMT(*LF)
MONMSG MSGID(CPF0000) EXEC(DO)
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('Errors +
occurred while copying STDOUT log to +
file. Check the joblog') +
MSGTYPE(*ESCAPE)
ENDDO
/* If copying results to IFS, do it now */
/* We copy from STDOUTQSH in QTEMP to IFS log */
IF COND(&IFSSTDOUT *EQ *YES) THEN(DO)
CPYTOSTMF +
FROMMBR('/QSYS.LIB/QTEMP.LIB/STDOUTQSH.FILE+
/STDOUTQSH.MBR') TOSTMF(&IFSFILE) +
STMFOPT(&IFSOPT) CVTDTA(*AUTO) +
STMFCCSID(*PCASCII) ENDLINFMT(*LF) +
STMFCODPAG(*STMF)
/* Prevent endless loop if CPYTOSTMF fails */
MONMSG MSGID(CPF0000) EXEC(DO)
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('Error +
copying log to IFS file' |> &IFSFILE |> +
'- QSHEXEC cancelled') MSGTYPE(*ESCAPE)
ENDDO
ENDDO
/* IF ENABLED, PRINT STDOUT RESULTS */
IF COND(&PRTSTDOUT *EQ *YES) THEN(DO)
/* PRINT STDOUT LOG NOW */
OVRPRTF FILE(QSYSPRT) TOFILE(QSYSPRT) PAGESIZE(198) +
PRTTXT(&PRTTXT) HOLD(*YES) +
USRDTA(&PRTUSRDTA) SPLFNAME(&PRTSPLF)
CPYF FROMFILE(QTEMP/STDOUTQSH) TOFILE(QSYSPRT)
DLTOVR FILE(QSYSPRT)
ENDDO
/* IF ENABLED, DISPLAY STDOUT RESULTS */
IF COND(&DSPSTDOUT *EQ *YES) THEN(DO)
EDTF STMF(&STDOUTIFS)
MONMSG MSGID(CPF0000)
ENDDO
/* IF ENABLED, Erase stdout result file */
IF COND(&DLTSTDOUT *EQ *YES) THEN(DO)
ERASE OBJLNK(&STDOUTIFS)
MONMSG MSGID(CPF0000)
ENDDO
/* Write STDOUT results PF to job log */
IF COND(&LOGSTDOUT *EQ *YES) THEN(DO)
OVRDBF FILE(STDOUTQSH) TOFILE(QTEMP/STDOUTQSH)
CALL PGM(QSHSTDOUTR)
DLTOVR FILE(STDOUTQSH)
ENDDO
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('QShell +
command failed') MSGTYPE(*ESCAPE)
ENDPGM:
ENDPGM