z/OS UNIX System Services User's Guide
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


OSHELL: Running a shell command from the TSO/E READY prompt

z/OS UNIX System Services User's Guide
SA23-2279-00

The OSHELL REXX exec, shipped in SYS1.SBPXEXEC, invokes BPXBATCH to run non-interactive shell commands from the TSO/E READY prompt. The output is displayed in your TSO/E session.

OSHELL usage notes: Note that:

  1. With OSHELL, you cannot use a shell command with an & (ampersand) to run it in the background.
  2. OSHELL cannot be used to invoke an interactive shell command.
  3. OSHELL creates a temporary file in the /tmp directory. The name of the temporary file includes the time, to avoid naming conflicts (for example, /tmp/userid1.12:33:32.461279.IBM). The file is deleted when OSHELL completes.

OSHELL examples: For example:

To delete the file dbtest.c, user TURBO would enter at the TSO/E READY prompt:
oshell rm -r /u/turbo/testdir/dbtest.c
To display the amount of free space in your file system, you could enter:
oshell df -P
To display information on all accessible processes, you could enter:
oshell ps -ej

Figure 1 shows how OSHELL is coded.

Figure 1. The OSHELL REXX exec
/* REXX */
parse arg shellcmd
username =,
TRANSLATE(userid(),'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')
/********************************************************************/
/* Free STDERR just in case it was left allocated                   */
/********************************************************************/
/*                                                                  */
msgs = msg('OFF')
"FREE DDNAME(STDERR)"
/********************************************************************/
"ALLOCATE FILE(STDOUT) PATH('/tmp/"username"."time('L')".IBM') ",
"PATHOPTS(OWRONLY,OCREAT,OEXCL,OTRUNC) PATHMODE(SIRWXU)",
"PATHDISP(DELETE,DELETE)"
IF RC ¬= 0 Then
  DO
    "FREE DDNAME(STDOUT)"
    "ALLOCATE FILE(STDOUT) PATH('/tmp/"username"."time('L')".IBM') ",
    "PATHOPTS(OWRONLY,OCREAT,OEXCL,OTRUNC) PATHMODE(SIRWXU)",
    "PATHDISP(DELETE,DELETE)"
    IF RC ¬= 0 Then
      DO
        msgs = msg(msgs)
        /* Allocate must have failed */
        Say ' This REXX exec failed to allocate STDOUT.'
        Say ' This REXX exec did not run shell command ' shellcmd
        RETURN
      END
  END
msgs = msg(msgs)

"BPXBATCH SH "shellcmd

IF RC ¬= 0 Then
   DO
     Say ' RC = ' RC
     Say ' '
   END
IF RC > 255 Then
   DO
     Say ' Exit Status = ' RC/256
     Say ' '
   END
IF (RC ¬= 254) & (RC ¬= 255) THEN
   DO
     "ALLOCATE FILE(out1) DA(*) LRECL(255) RECFM(F) REUSE"
     "OCOPY indd(STDOUT) outdd(out1) TEXT PATHOPTS(OVERRIDE)"
     "FREE DDNAME(out1)"
   END
"FREE DDNAME(STDOUT)"

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014