z/OS UNIX shell script
As documented in UNIX System
Services Command Reference (SA22-7802), z/OS® UNIX offers
the su command to use the privileges of a superuser
or another user. There are few things to keep in mind when using the su command.
- The user ID executing the su command must
have READ permission to the
BPX.SRV.<userid>
profile in theSURROGAT
class of your security product to be able to switch to the user ID identified by<userid>
without specifying a password. - The su command starts a new shell, so the remaining commands in your shell script will not be executed until the shell started by the su command exits. In order to stage commands to be executed in the new shell started by the su command, you can use the echo command to create the desired command and the pipe command character to feed it into the new shell, as shown in the following example. Note that standard shell scripting rules apply for escaping special characters.
#! /bin/sh
myID=ibmuser
echo a $(id)
echo 'echo b $(id)' | su –s $myID
echo "echo c \$(id)" | su –s $myID
cat /u/ibmuser/iefbr14
echo "submit /u/ibmuser/iefbr14" | su –s $myID
This sample logon exit, executed by the started task user ID, will result in the following console messages:
+FEK910I LOGON EXIT: invoking logon processing exit in thread 411
+FEK910I LOGON EXIT: a uid=8(STCRSE) gid=1(STCGROUP)
+FEK910I LOGON EXIT: b uid=1(IBMUSER) gid=0(SYS1)
+FEK910I LOGON EXIT: c uid=1(IBMUSER) gid=0(SYS1)
+FEK910I LOGON EXIT: //IEFBR14 JOB CLASS=A,MSGCLASS=A,MSGLEVEL=(1,1)
+FEK910I LOGON EXIT: //IEFBR14 EXEC PGM=IEFBR14
$HASP100 IEFBR14 ON INTRDR FROM STC03919
IBMUSER
IRR010I USERID IBMUSER IS ASSIGNED TO THIS JOB.
+FEK910I LOGON EXIT: JOB JOB03926 submitted from path '/u/ibmuser/iefbr14'
ICH70001I IBMUSER LAST ACCESS AT 00:46:13 ON MONDAY, MARCH 19, 2012
$HASP373 IEFBR14 STARTED - INIT 2 - CLASS A - SYS CD08
IEF403I IEFBR14 - STARTED - TIME=00.46.14
+FEK910I LOGON EXIT: completed logon processing exit in thread 411
IEFBR14 IEFBR14 IEFBR14 0000
IEF404I IEFBR14 - ENDED - TIME=00.46.14
$HASP395 IEFBR14 ENDED
$HASP309 INIT 2 INACTIVE ******** C=BA