-
Notifications
You must be signed in to change notification settings - Fork 22
/
ispfcmd.sh
executable file
·162 lines (142 loc) · 4.04 KB
/
ispfcmd.sh
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
#!/bin/sh
#
# run an ispf command under a vanilla ISPF environment
# See https://tech.mikefulton.ca/BatchISPF for details on running ISPF in batch
#
# Copyright IBM Corp. 2021
#
function ISPFDDDefine {
ds=$1
usrds=$2
if [ "${usrds}" = "" ]; then
echo "${ds}"
else
echo "${usrds}:${ds}"
fi
return 0
}
function ISPFDDOverride {
ds=$1
usrds=$2
if [ "${usrds}" = "" ]; then
echo "${ds}"
else
echo "${usrds}"
fi
return 0
}
function ISPFTempDS {
tmp=`mvstmp $(hlq)`
dtouch ${tmp}
rc=$?
echo "${tmp}"
return $rc
}
function ISPFRmDS {
drm $1
}
function Syntax {
echo "$0 [opts]" >&2
echo "Run the command(s) specified under ISPF." >&2
echo "By default, ISPF runs a minimal environment." >&2
echo "Each DDName can be overridden by exporting the corresponding environment variable to " >&2
echo " specify the concatenated datasets needed. ISPF base datasets will be appended to the end of the list." >&2
echo "Options:" >&2
echo " -h : Print this help." >&2
echo " -v : Verbose mode - print out the DDNames sent to batch TSO (IKJEFT1B)." >&2
echo " - : Read the SYSTSIN DDName data from stdin, not from a dataset." >&2
echo "Note:" >&2
echo " The ISPF datasets need to be allocated as part of running a command under ISPF." >&2
echo " export ISPF_HLQ=<hlq> to indicate the high level qualifier for the ISPF datasets. Default is ISP." >&2
echo "Example 1:" >&2
echo " Read SYSTSIN from stdin. Run the program HW from library IBMUSER.USER.LOAD under ISPF. Turn off output from SYSTSPRT by setting the DDName to DUMMY." >&2
echo " (export SYSTSPRT=DUMMY; export ISPLLIB=IBMUSER.USER.LOAD; echo ' ISPSTART PGM(HW)' | ispfcmd.sh -)" >&2
echo "Example 2:" >&2
echo " Read SYSTSIN from stdin. Print out the DDNames to stdout. Run the REXX exec HW from IBMUSER.USER.REXX dataset." >&2
echo " (export SYSEXEC=IBMUSER.USER.REXX; echo ' ISPSTART CMD(HW)' | ./ispfcmd.sh -v -) "
}
#
# Mainline
#
#set -x
verbose=false
redirect=false
while getopts ":vh" opt; do
case ${opt} in
v )
verbose=true
;;
h )
Syntax
exit 4
;;
\?)
if [ ${OPTARG} != "?" ]; then
echo "Unknown Option: ${OPTARG}" >&2
fi
Syntax
exit 4
;;
esac
done
shift $(expr $OPTIND - 1 )
if [ $# -eq 1 ] && [ "$1" = "-" ]; then
redirect=true
shift 1
fi
if [ $# -ne 0 ]; then
Syntax
exit 8
fi
if ${redirect}; then
SYSTSIN=`cat`
else
if [ "${SYSTSIN}" = "" ]; then
echo "Need to either provide SYSTSIN data from stdin or export SYSTSIN to the dataset to read" >&2
Syntax
exit 8
fi
fi
if [ "${ISPF_HLQ}" = "" ]; then
ISPF_HLQ='ISP'
fi
ISPLLIB=`ISPFDDOverride DUMMY ${ISPLLIB}`
ISPMLIB=`ISPFDDDefine "${ISPF_HLQ}.SISPMENU" ${ISPMLIB}`
ISPPLIB=`ISPFDDDefine "${ISPF_HLQ}.SISPMENU" ${ISPPLIB}`
ISPSLIB=`ISPFDDDefine "${ISPF_HLQ}.SISPSENU:${ISPF_HLQ}.SISPSLIB" ${ISPSLIB}`
ISPPROF_TMP=`ISPFTempDS`
if [ $? -gt 0 ]; then
exit 4
fi
ISPTLIB_TMP=`ISPFTempDS`
if [ $? -gt 0 ]; then
exit 4
fi
ISPTLIB=`ISPFDDDefine "${ISPF_HLQ}.SISPTENU" "${ISPTLIB}"`
SYSEXEC=`ISPFDDDefine "${ISPF_HLQ}.SISPEXEC" "${SYSEXEC}"`
SYSPROC=`ISPFDDDefine "${ISPF_HLQ}.SISPCLIB" "${SYSPROC}"`
ISPTLIB=`ISPFDDDefine "${ISPF_HLQ}.SISPTENU" "${ISPTLIB_TMP}"`
ISPLOG=`ISPFDDOverride DUMMY "${ISPLOG}"`
ISPCTL1=`ISPFDDOverride DUMMY "${ISPCTL1}"`
SYSTSPRT=`ISPFDDOverride stdout "${SYSTSPRT}"`
SYSPRINT=`ISPFDDOverride stdout "${SYSPRINT}"`
if [ "${ISPLLIB}" = "DUMMY" ]; then
ISPLLIBDD=""
else
ISPLLIBDD="--ISPLLIB=${ISPLLIB}"
fi
parms="--pgm=IKJEFT1B --ISPPROF=${ISPPROF_TMP} ${ISPLLIBDD} --ISPMLIB=${ISPMLIB} --ISPPLIB=${ISPPLIB}\
--ISPSLIB=${ISPSLIB} --ISPTLIB=${ISPTLIB} --ISPCTL1=${ISPCTL1} --ISPLOG=${ISPLOG}\
--SYSEXEC=${SYSEXEC} --SYSPROC=${SYSPROC} --SYSTSPRT=${SYSTSPRT} --SYSPRINT=${SYSPRINT}"
if ${verbose}; then
echo "mvscmdauth ${parms}"
fi
if ${redirect}; then
echo "${SYSTSIN}" | mvscmdauth ${parms} --SYSTSIN=stdin
else
mvscmdauth ${parms} --SYSTSIN=${SYSTSIN}
fi
rc=$?
ISPFRmDS ${ISPPROF_TMP}
ISPFRmDS ${ISPTLIB_TMP}
exit $rc