X-Mailer: ELM [version 2.4beta PL13]
Content-Type: text
Content-Length: 2977
Newsgroups: bit.listserv.cmspip-l
Date:         Fri, 6 Nov 1992 15:43:14 -0500
From:         "(Joseph D. McMahon)" <xrjdm@CALVIN.GSFC.NASA.GOV>
Subject:      Interfacing TSSO's OSCMD and Pipes

As the result of either inspiration or too much coffee :-), I've come up
with a method of capturing output from TSSO's OSCMD command and routing
it into a pipe. A bit of explanation would be useful here...

TSSO is an operations automation tool available for FREE on the CBT tape.
It can intercept messages and issue commands in response to them; in
addition, it can also issue TSO commands at the console, and provides
an interface which allows TSO CLISTs (not REXX, just CLISTs) to issue
system commands and capture the output.

The OSCMD command (the system command interface) provides a means of
capturing command output into CLIST variables. It does not work properly
with REXX variables or stems. However, there is a way atound this. The
following CLIST and REXX filter provide an interface between OSCMD
and Pipes.

----

OS CLIST:

PROC 0 CMD()

SET CMDRESP=CLIST    /* point OSCMD's output to CLIST variables */
SET CMDWAIT=5        /* Wait for 5 seconds for the command to execute */
SET MAXCMDOUT=200    /* Capture up to 200 lines of output */

OSCMD &CMD           /* Issue the command */

SET I = 2            /* Start after command echo on line 1 */

DO WHILE &I <= &CMDOUT   /* Loop until all lines are processed */
  SET OUTLIN = &STR(&&CMDOUT&I)    /* Get next line */
  WRITE &OUTLIN          /* Send to output with TSO standard I/O */
  SET I = &I + 1         /* Next line */
  END                    /* of WHILE loop */

EXIT CODE(0)         /* Successful execution */

----

TSOCMD command:

/* REXX - execute a TSO command and write its output to a file */

arg cmd

z = OUTTRAP(cmdout.,100)
ADDRESS TSO cmd
z = OUTTRAP(OFF)

ADDRESS TSO
  "alloc f(TSOPIPOT) UNIT(TEMPDA) NEW SP(1) CYL REUSE"
  "EXECIO * DISKW TSOPIPOT (STEM cmdout."

return

----

TSOLIT Filter:

/* REXX - filter stage to execute a TSO command and send output into a pipe */

signal on error

arg x

"callpipe var x",
	 "|change ,,tsocmd ,",
	 "|command"
"callpipe qsam tsopipot |*:"

exit

error: return RC*(RC^=12)

----

A sample OSCMD-driven filter (TOSMTP):

/* REXX - Reroute a job to SMTP

   This REXX EXEC is a Pipes filter which treats the first word of the
   primary input stream as a job number and issues a JES2 $TOJ command
   to reroute the job to SMTP (locally). The command output is sent to
   the primary output stream.

   Example: PIPE literal 1234|rexx tosmtp|console

 */

X = ''

do forever
   if X = '' then 'readto X'
   parse var X jobumber .
   "callpipe var X",
     "|spec /tsocmd os cmd('$TOJ/ 1 1-5 next /,OUTGRP=1.1.1,D=SMTP')/ next",
     "|command"

   "callpipe qsam tsopipot|*:"
   X = ''
   end

error: return RC * (RC ^= 12)

----

Thanks again to the original author of the TSOCMD filter (whose name I've
misplaced). The only really cute little items are the trick in TOSMTP where
the command is built by piecing it together with SPEC, and the trick of
using a CLIST to force the output to come out in the standard manner.

 --- Joe M.
Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU