Re: Running z/OS Unix commands from an MVS sequential dataset

2022-04-04 Thread Farley, Peter x23353
Thanks again Kirk - I too love those goofy shell quotes ().

Could also conceivably use a "here document" for the inputs to the first awk  
and just have all the DSN's in-stream with the commands, but that would be 
showing off 😊.

Peter

-Original Message-
From: MVS OpenEdition  On Behalf Of Kirk Wolf
Sent: Monday, April 4, 2022 7:31 PM
To: mvs...@vm.marist.edu
Subject: Re: Running z/OS Unix commands from an MVS sequential dataset

xargs takes a command template and runs it with all of the words read from 
stdin tacked on as args.   This works well with awk since it takes a list of 
filenames to process as arguments.

FWIW, you can also use awk to read a list of dsns (without "//'...'" ).  This 
also shows that since awk uses fopen that it can read from DDs if it's run in 
the same address space as the shell.   For Gil :-)

//AWK  EXEC PGM=COZBATCH
//DSNS DD   *
SYS1.MACLIB(ACB)
SYS1.MACLIB(CHECK)
SYS1.MACLIB(CLOSE)
SYS1.MACLIB(DYNALLOC)
/*
//STDIN DD  *
awk '{print "\"//'\''" $1 "'\''\"" }' //DD:DSNS |
  xargs awk '/STR/ {print FILENAME ":" NR "\t" $0 }'
//

But I mostly like it because of the goofy shell quoting that it required :-)

On Mon, Apr 4, 2022, at 5:53 PM, Farley, Peter x23353 wrote:
> Thanks for the awk idea Kirk, I should have considered that solution myself.  
> I need to read up on the xargs command first though, I have not used it and 
> need a better understanding of how it works.
>
> Peter
>
> -----Original Message-
> From: MVS OpenEdition  On Behalf Of Kirk Wolf
> Sent: Monday, April 4, 2022 12:48 PM
> To: mvs...@vm.marist.edu
> Subject: Re: Running z/OS Unix commands from an MVS sequential dataset
>
> EXTERNAL EMAIL
>
> This is how I would do it.
>
> - You can make awk not only act like (f)grep, but it also takes dsn 
> syntax  since uses fopen()
> - awk will also read multiple files in one execution, so this will run rings 
> around other ways that require a couple of forks for every dsn that you are 
> searching.
> - you can also customize how the output looks (see below)
>
> //AWK  EXEC PGM=COZBATCH
> //DSNS DD   *
> "//'SYS1.MACLIB(ACB)'"
> "//'SYS1.MACLIB(CHECK)'"
> "//'SYS1.MACLIB(CLOSE)'"
> "//'SYS1.MACLIB(DYNALLOC)'"
> /*
> //STDIN DD  *
> fromdsn //DD:DSNS |
>   xargs awk '/STR/ {print FILENAME ":" NR "\t" $0 }'
> //
>
> Replace STR above with your regex.
> You can make this work with BPXBATCH and cat instead of fromdsn, but 
> its not nearly as slick :-)
>
> Kirk Wolf
> Dovetailed Technologies
> https://urldefense.com/v3/__http://dovetail.com__;!!Ebr-cpPeAnfNniQ8HS
> AI-g_K5b7VKg!YWy9o1XPpMwBL-at2HSefZAJ0ORxBp0McqmDmjob2R2NodfjeaVxqa6Fc
> W_0T5fCjUVbIA$
>
> Co:Z Toolkit is free to use under the terms of our Community License.   
> Commercial license and support agreements are available.
>
>
> On Sun, Apr 3, 2022, at 4:06 PM, Farley, Peter x23353 wrote:
> > Thanks for the "fgrep -n" suggestion, that will definitely help in solving 
> > the actual business issue.
> >
> > Using "sh -x" is not as helpful though because although you get a separate 
> > output line for the "cat" of the MVS data set (good, would allow removal of 
> > the "echo" command) but you also get another line for the piped "fgrep" 
> > (not-so -useful noise).
> >
> > Now if fgrep actually accepted MVS data set syntax on its command line like 
> > awk does then "sh -x" would be very useful, since the only command 
> > necessary would be fgrep.  Perhaps the coming "unification" of the file 
> > systems will help (once my employer's systems get to that OS level at some 
> > fairly long time post-GA).
> >
> > Thanks again for your prompt and helpful assistance.
> >
> > Peter
> >
> > -Original Message-
> > From: IBM Mainframe Discussion List  On 
> > Behalf Of Paul Gilmartin
> > Sent: Sunday, April 3, 2022 4:40 PM
> > To: IBM-MAIN@LISTSERV.UA.EDU
> > Subject: Re: Running z/OS Unix commands from an MVS sequential 
> > dataset
> >
> > On Sun, 3 Apr 2022 19:35:34 +, Farley, Peter x23353 wrote:
> >
> > >That worked, got output to STDOUT as desired.
> > >
> > Yaaay!  (With no setup copy?)
> >
> > >Thankoyou for your help!
> > >
> > You' re welcome.  A couple extra thoughts:
> > // PARM='SH  /bin/cp //"''TSOUSER.UNIXCMDS.SH''" /dev/fd/1 | /bin/sh -x 
> >

Re: Running z/OS Unix commands from an MVS sequential dataset

2022-04-04 Thread Farley, Peter x23353
Thanks for the awk idea Kirk, I should have considered that solution myself.  I 
need to read up on the xargs command first though, I have not used it and need 
a better understanding of how it works.

Peter

-Original Message-
From: MVS OpenEdition  On Behalf Of Kirk Wolf
Sent: Monday, April 4, 2022 12:48 PM
To: mvs...@vm.marist.edu
Subject: Re: Running z/OS Unix commands from an MVS sequential dataset

EXTERNAL EMAIL

This is how I would do it.

- You can make awk not only act like (f)grep, but it also takes dsn syntax  
since uses fopen()
- awk will also read multiple files in one execution, so this will run rings 
around other ways that require a couple of forks for every dsn that you are 
searching.
- you can also customize how the output looks (see below)

//AWK  EXEC PGM=COZBATCH
//DSNS DD   *
"//'SYS1.MACLIB(ACB)'"
"//'SYS1.MACLIB(CHECK)'"
"//'SYS1.MACLIB(CLOSE)'"
"//'SYS1.MACLIB(DYNALLOC)'"
/*
//STDIN DD  *
fromdsn //DD:DSNS |
  xargs awk '/STR/ {print FILENAME ":" NR "\t" $0 }'
//

Replace STR above with your regex.
You can make this work with BPXBATCH and cat instead of fromdsn, but its not 
nearly as slick :-)

Kirk Wolf
Dovetailed Technologies
https://urldefense.com/v3/__http://dovetail.com__;!!Ebr-cpPeAnfNniQ8HSAI-g_K5b7VKg!YWy9o1XPpMwBL-at2HSefZAJ0ORxBp0McqmDmjob2R2NodfjeaVxqa6FcW_0T5fCjUVbIA$
 

Co:Z Toolkit is free to use under the terms of our Community License.   
Commercial license and support agreements are available.


On Sun, Apr 3, 2022, at 4:06 PM, Farley, Peter x23353 wrote:
> Thanks for the "fgrep -n" suggestion, that will definitely help in solving 
> the actual business issue.
>
> Using "sh -x" is not as helpful though because although you get a separate 
> output line for the "cat" of the MVS data set (good, would allow removal of 
> the "echo" command) but you also get another line for the piped "fgrep" 
> (not-so -useful noise).
>
> Now if fgrep actually accepted MVS data set syntax on its command line like 
> awk does then "sh -x" would be very useful, since the only command necessary 
> would be fgrep.  Perhaps the coming "unification" of the file systems will 
> help (once my employer's systems get to that OS level at some fairly long 
> time post-GA).
>
> Thanks again for your prompt and helpful assistance.
>
> Peter
>
> -Original Message-
> From: IBM Mainframe Discussion List  On 
> Behalf Of Paul Gilmartin
> Sent: Sunday, April 3, 2022 4:40 PM
> To: IBM-MAIN@LISTSERV.UA.EDU
> Subject: Re: Running z/OS Unix commands from an MVS sequential dataset
>
> On Sun, 3 Apr 2022 19:35:34 +, Farley, Peter x23353 wrote:
>
> >That worked, got output to STDOUT as desired.
> >
> Yaaay!  (With no setup copy?)
>
> >Thankoyou for your help!
> >
> You' re welcome.  A couple extra thoughts:
> // PARM='SH  /bin/cp //"''TSOUSER.UNIXCMDS.SH''" /dev/fd/1 | /bin/sh -x 
> 2>&1'
>
> "-x" logs the commands to identify data sets, merging that log with stdout.
>
> "fgrep -n" numbers the lines.
--

This message and any attachments are intended only for the use of the addressee 
and may contain information that is privileged and confidential. If the reader 
of the message is not the intended recipient or an authorized representative of 
the intended recipient, you are hereby notified that any dissemination of this 
communication is strictly prohibited. If you have received this communication 
in error, please notify us immediately by e-mail and delete the message and any 
attachments from your system.

--
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN


Re: Running z/OS Unix commands from an MVS sequential dataset

2022-04-03 Thread Rob Schramm
If you come across low values, binary, you may experience an issue that you
weren't expecting.

Rob

On Sun, Apr 3, 2022, 17:36 Paul Gilmartin <
000433f07816-dmarc-requ...@listserv.ua.edu> wrote:

> On Sun, 3 Apr 2022 21:06:05 +, Farley, Peter x23353 wrote:
> >
> >Using "sh -x" is not as helpful though because although you get a
> separate output line for the "cat" of the MVS data set (good, would allow
> removal of the "echo" command) but you also get another line for the piped
> "fgrep" (not-so -useful noise).
> >
> Perhaps a function which could be defined at the top of your
> control file (untested, as seems to be my habit):
> FindIt(){
> if Result=$( cp "$1" /dev/fd/1 |
>  fgrep -n STRNIG_TO_FIND )
> then
> printf '\nFound in %s\n%s\n' "$1" "$Result"
> fi; }
>
> --
> gil
>
> --
> For IBM-MAIN subscribe / signoff / archive access instructions,
> send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN
>

--
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN


Re: Running z/OS Unix commands from an MVS sequential dataset

2022-04-03 Thread Paul Gilmartin
On Sun, 3 Apr 2022 21:06:05 +, Farley, Peter x23353 wrote:
>
>Using "sh -x" is not as helpful though because although you get a separate 
>output line for the "cat" of the MVS data set (good, would allow removal of 
>the "echo" command) but you also get another line for the piped "fgrep" 
>(not-so -useful noise).
>
Perhaps a function which could be defined at the top of your
control file (untested, as seems to be my habit):
FindIt(){
if Result=$( cp "$1" /dev/fd/1 |
 fgrep -n STRNIG_TO_FIND )
then
printf '\nFound in %s\n%s\n' "$1" "$Result"
fi; }

-- 
gil

--
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN


Re: Running z/OS Unix commands from an MVS sequential dataset

2022-04-03 Thread Farley, Peter x23353
Thanks for the "fgrep -n" suggestion, that will definitely help in solving the 
actual business issue.

Using "sh -x" is not as helpful though because although you get a separate 
output line for the "cat" of the MVS data set (good, would allow removal of the 
"echo" command) but you also get another line for the piped "fgrep" (not-so 
-useful noise).

Now if fgrep actually accepted MVS data set syntax on its command line like awk 
does then "sh -x" would be very useful, since the only command necessary would 
be fgrep.  Perhaps the coming "unification" of the file systems will help (once 
my employer's systems get to that OS level at some fairly long time post-GA).

Thanks again for your prompt and helpful assistance.

Peter

-Original Message-
From: IBM Mainframe Discussion List  On Behalf Of 
Paul Gilmartin
Sent: Sunday, April 3, 2022 4:40 PM
To: IBM-MAIN@LISTSERV.UA.EDU
Subject: Re: Running z/OS Unix commands from an MVS sequential dataset

EXTERNAL EMAIL

On Sun, 3 Apr 2022 19:35:34 +, Farley, Peter x23353 wrote:

>That worked, got output to STDOUT as desired.
> 
Yaaay!  (With no setup copy?)

>Thankoyou for your help!
> 
You' re welcome.  A couple extra thoughts:
// PARM='SH  /bin/cp //"''TSOUSER.UNIXCMDS.SH''" /dev/fd/1 | /bin/sh -x 
2>&1'

"-x" logs the commands to identify data sets, merging that log with stdout.

"fgrep -n" numbers the lines.

--


This message and any attachments are intended only for the use of the addressee 
and may contain information that is privileged and confidential. If the reader 
of the message is not the intended recipient or an authorized representative of 
the intended recipient, you are hereby notified that any dissemination of this 
communication is strictly prohibited. If you have received this communication 
in error, please notify us immediately by e-mail and delete the message and any 
attachments from your system.


--
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN


Re: Running z/OS Unix commands from an MVS sequential dataset

2022-04-03 Thread Paul Gilmartin
On Sun, 3 Apr 2022 19:35:34 +, Farley, Peter x23353 wrote:

>That worked, got output to STDOUT as desired.
> 
Yaaay!  (With no setup copy?)

>Thankoyou for your help!
> 
You' re welcome.  A couple extra thoughts:
// PARM='SH  /bin/cp //"''TSOUSER.UNIXCMDS.SH''" /dev/fd/1 | /bin/sh -x 
2>&1'

"-x" logs the commands to identify data sets, merging that log with stdout.

"fgrep -n" numbers the lines.

-- 
gil

--
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN


Re: Running z/OS Unix commands from an MVS sequential dataset

2022-04-03 Thread Farley, Peter x23353
That worked, got output to STDOUT as desired.

Thank you for your help!

Peter

-Original Message-
From: IBM Mainframe Discussion List  On Behalf Of 
Paul Gilmartin
Sent: Sunday, April 3, 2022 3:14 PM
To: IBM-MAIN@LISTSERV.UA.EDU
Subject: Re: Running z/OS Unix commands from an MVS sequential dataset

EXTERNAL EMAIL

On Sun, 3 Apr 2022 19:01:09 +, Farley, Peter x23353 wrote:

>Good try, but I got the same STDERR results as the first one - the pipe 
>operator is still being ignored by the PGM invocation.
> 
Use "SH", not "PGM".


>Might also need a "chmod 700 /tmp/temp,sh" after the copy to /tmp is done for 
>that first SH syntax.  I'll try both and see what I can do.
>
>I had also earlier tried
>
>// PARM='SH . //"''TSOUSER.UNIXCMDS.SH''"'
>
>but that method cannot seem to find the MVS file.


>-Original Message-
>From: IBM Mainframe Discussion List  On 
>Behalf Of Paul Gilmartin
>Sent: Sunday, April 3, 2022 2:41 PM'
>> ...
>Oops!  PGM doesn't understand Shell syntax.  Maybe:
>// PARM='SH  /bin/cp //"''TSOUSER.UNIXCMDS.SH''" /dev/fd/1 | /bin/sh'

--


This message and any attachments are intended only for the use of the addressee 
and may contain information that is privileged and confidential. If the reader 
of the message is not the intended recipient or an authorized representative of 
the intended recipient, you are hereby notified that any dissemination of this 
communication is strictly prohibited. If you have received this communication 
in error, please notify us immediately by e-mail and delete the message and any 
attachments from your system.


--
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN


Re: Running z/OS Unix commands from an MVS sequential dataset

2022-04-03 Thread Paul Gilmartin
On Sun, 3 Apr 2022 19:01:09 +, Farley, Peter x23353 wrote:

>Good try, but I got the same STDERR results as the first one - the pipe 
>operator is still being ignored by the PGM invocation.
> 
Use "SH", not "PGM".


>Might also need a "chmod 700 /tmp/temp,sh" after the copy to /tmp is done for 
>that first SH syntax.  I'll try both and see what I can do.
>
>I had also earlier tried
>
>// PARM='SH . //"''TSOUSER.UNIXCMDS.SH''"'
>
>but that method cannot seem to find the MVS file.


>-Original Message-
>From: IBM Mainframe Discussion List  On Behalf Of 
>Paul Gilmartin
>Sent: Sunday, April 3, 2022 2:41 PM'
>> ...
>Oops!  PGM doesn't understand Shell syntax.  Maybe:
>// PARM='SH  /bin/cp //"''TSOUSER.UNIXCMDS.SH''" /dev/fd/1 | /bin/sh'

-- 
gil

--
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN


Re: Running z/OS Unix commands from an MVS sequential dataset

2022-04-03 Thread Paul Gilmartin
On Sun, 3 Apr 2022 18:48:31 +, Farley, Peter x23353 wrote:

>Thanks Gil.  Tried your suggestion, but got this in STDERR:
>
>cp: FSUM4262 target "/bin/sh" must be a directory
>cp: or a partitioned data set
>
>It would seem that the PGM invocation does not recognize or just ignores the 
>pipe operator.
> 
It took it as a filename.

I remembered that too late and submitted a correction.

Fortunately, it didn't overwrite /bin/sh.

-- 
gil

--
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN


Re: Running z/OS Unix commands from an MVS sequential dataset

2022-04-03 Thread Farley, Peter x23353
Good try, but I got the same STDERR results as the first one - the pipe 
operator is still being ignored by the PGM invocation.

I guess I have no real choice but to cp the MVS file to /tmp and run it from 
there with something like:

// PARM='SH /tmp/temp.sh'  or // PARM='SH . /tmp/temp.sh'

Might also need a "chmod 700 /tmp/temp,sh" after the copy to /tmp is done for 
that first SH syntax.  I'll try both and see what I can do.

I had also earlier tried

// PARM='SH . //"''TSOUSER.UNIXCMDS.SH''"'

but that method cannot seem to find the MVS file.

Peter

-Original Message-
From: IBM Mainframe Discussion List  On Behalf Of 
Paul Gilmartin
Sent: Sunday, April 3, 2022 2:41 PM
To: IBM-MAIN@LISTSERV.UA.EDU
Subject: Re: Running z/OS Unix commands from an MVS sequential dataset

On Apr 3, 2022, at 12:26:58, Paul Gilmartin wrote:
>> 
> I'll suggest
>// PARM='PGM /bin/cp //"''TSOUSER.UNIXCMDS.SH''" | /bin/sh'
> 
Oops!  PGM doesn't understand Shell syntax.  Maybe:
// PARM='SH  /bin/cp //"''TSOUSER.UNIXCMDS.SH''" /dev/fd/1 | /bin/sh'

--

This message and any attachments are intended only for the use of the addressee 
and may contain information that is privileged and confidential. If the reader 
of the message is not the intended recipient or an authorized representative of 
the intended recipient, you are hereby notified that any dissemination of this 
communication is strictly prohibited. If you have received this communication 
in error, please notify us immediately by e-mail and delete the message and any 
attachments from your system.

--
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN


Re: Running z/OS Unix commands from an MVS sequential dataset

2022-04-03 Thread Farley, Peter x23353
Thanks Gil.  Tried your suggestion, but got this in STDERR:

cp: FSUM4262 target "/bin/sh" must be a directory
cp: or a partitioned data set

It would seem that the PGM invocation does not recognize or just ignores the 
pipe operator.

Peter

-Original Message-
From: IBM Mainframe Discussion List  On Behalf Of 
Paul Gilmartin
Sent: Sunday, April 3, 2022 2:27 PM
To: IBM-MAIN@LISTSERV.UA.EDU
Subject: Re: Running z/OS Unix commands from an MVS sequential dataset

On Apr 3, 2022, at 11:53:23, Farley, Peter x23353 wrote:
> 
> CC'ed to IBM-MAIN for a wider audience.
> 
> DSN='TSOUSER.PDS(MEMBER01)'
> echo $DSN
> cat //"'$DSN'" | fgrep ''' STRING-TO-FIND '''
>  
"cat //" ..." Is not documented as supported, but it sometimes Works, so that 
may not be the cause of your problem.
"cp //... /dev/fd/1 | ..;" is documented as supported.

> I have tried this JCL to accomplish running the commands from a file.  It 
> runs with CC=0, but STDOUT is never populated:
> 
> //RUNCMDS EXEC BPXBATCH,REGION=256M,
> // PARM='PGM /bin/sh . //"''TSOUSER.UNIXCMDS.SH''"'
> //STDOUT DD SYSOUT=*
> //STDERR DD SYSOUT=*
> //STDIN DD DUMMY
>  
I'll suggest
// PARM='PGM /bin/cp //"''TSOUSER.UNIXCMDS.SH''" | /bin/sh'

--

This message and any attachments are intended only for the use of the addressee 
and may contain information that is privileged and confidential. If the reader 
of the message is not the intended recipient or an authorized representative of 
the intended recipient, you are hereby notified that any dissemination of this 
communication is strictly prohibited. If you have received this communication 
in error, please notify us immediately by e-mail and delete the message and any 
attachments from your system.

--
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN


Re: Running z/OS Unix commands from an MVS sequential dataset

2022-04-03 Thread Paul Gilmartin
On Apr 3, 2022, at 12:26:58, Paul Gilmartin wrote:
>> 
> I'll suggest
>// PARM='PGM /bin/cp //"''TSOUSER.UNIXCMDS.SH''" | /bin/sh'
> 
Oops!  PGM doesn't understand Shell syntax.  Maybe:
// PARM='SH  /bin/cp //"''TSOUSER.UNIXCMDS.SH''" /dev/fd/1 | /bin/sh'

-- 
gil

--
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN


Re: Running z/OS Unix commands from an MVS sequential dataset

2022-04-03 Thread Paul Gilmartin
On Apr 3, 2022, at 11:53:23, Farley, Peter x23353 wrote:
> 
> CC'ed to IBM-MAIN for a wider audience.
> 
> DSN='TSOUSER.PDS(MEMBER01)'
> echo $DSN
> cat //"'$DSN'" | fgrep ''' STRING-TO-FIND '''
>  
"cat //" ..." Is not documented as supported, but it sometimes
Works, so that may not be the cause of your problem.
"cp //... /dev/fd/1 | ..;" is documented as supported.

> I have tried this JCL to accomplish running the commands from a file.  It 
> runs with CC=0, but STDOUT is never populated:
> 
> //RUNCMDS EXEC BPXBATCH,REGION=256M,
> // PARM='PGM /bin/sh . //"''TSOUSER.UNIXCMDS.SH''"'
> //STDOUT DD SYSOUT=*
> //STDERR DD SYSOUT=*
> //STDIN DD DUMMY
>  
I'll suggest
// PARM='PGM /bin/cp //"''TSOUSER.UNIXCMDS.SH''" | /bin/sh'

-- 
gil

--
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN