Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

ZOC REXX how to send server output to file

ZOC REXX how to send server output to file

ZOC REXX how to send server output to file

Be kind as I've just started playing with REXX via ZOC to login to a list of devices and automate some commands. It's come up that I need to send some device output to a file and I'm getting stuck trying to figure the output part out. See below where the script collects a login and password, then reads a file containing some IP addresses. The script logs into each server in the list and runs pwd (as an example). How do I get the output of pwd into a file instead (or in addition) to showing up on the screen?


login= ZocAsk("Enter Login")
pwd= ZocAsk("Enter Password")

file = "c:\input\ipList.txt"
do while( lines(file) )
Parse Var data v1

Call ZocTimeout 600

Call ZocSetDevice "Secure Shell"
Call ZocConnect login||":"pwd||"@"v1
Call ZocWait "[vt100]=>"
Call ZocSend "^M"
Call ZocSend "^M"
Call ZocSend "pwd^M" <--- How to send this output to a file appending every time through the loop
Call ZocSend "exit^M"



RE: ZOC REXX how to send server output to file

REXX by itself has no I/O model. All I/O services have to be provided by the environment in which the REXX code is operating. Thus in VM and MVS, REXX uses EXECIO to read and write data. Some implementations of REXX support CHARIN, CHAROUT, LINEIN, and LINEOUT. Your best bet is to see what the ZOC documentation recommends. I think you're not going to find many ZOC experts here. Best case scenario: You are going to become the resident ZOC expert.

Frank Clarke
--America's source for adverse opinions since 1943.

RE: ZOC REXX how to send server output to file

Well if I'm the expert, we're all doomed....lol. ZOC does support LINEOUT so I guess I'll need to do some research and see if I can fine some syntax and examples assuming that's the tree I should be barking up.

Essentially, I'm trying to ssh into several devices read in from a file and run a single command. That's all working based on by example. The command being run outputs 3 lines of text. I need to output those 3 lines of text to a file. i.e. - if I had 10 devices listed in my input file, I would end up with 1 output file with 30 lines of text.


RE: ZOC REXX how to send server output to file

Try to look at ZocReceiveBuf and ZocString
With ZocReceiveBuf you can receive the output of the command into memory and then write it into variable. With ZocString you can get the number of lines stored in the variable (which contains the command output) and you can retrieve individual lines.
Look here https://www.emtec.com/zoc/documents.html#rexxfiles
at ZOC REXX Reference https://www.emtec.com/downloads/zoc/rexx/docs/ZocR...
and the examples from ZocScriptingSamples.zip https://www.emtec.com/downloads/zoc/rexx/ZocScript...
e.g. these examples

RE: ZOC REXX how to send server output to file

Thanks both for the help. I worked on it this morning with LINEOUT and saw the zoclastline in the manual. That then recommended a look at ZocReceiveBuf. It might not be that sexy but I just added a couple lines above and below my command I was sending to the devices "show image ver" and ended up with this:

Call ZocReceiveBuf 512
Call ZocSend "show image ver^M"
Call ZocWait "#"
output= ZocReceiveBuf(512)

This totally gives me something usable and now maybe I'll use the new info from mikrom about ZocString to class up the output formatting a bit. I'm ecstatic! Thanks!!!!!


RE: ZOC REXX how to send server output to file

As described on the page 161 of the ZOC REXX Reference you could try to create ZocReceiveBuffer of a specific size, save the output of some commands in it, write the buffer into a variable and then into a file.

I don't know ZOC, but I would try to do something like this:


/* start receiving output into buffer of an specific size */
call ZocReceiveBuf 1024
your commands come here
/* at end, stop buffering, and save the content of the buffer into a variable */
data= ZocReceiveBuf(0)

/* get number of lines contained in the variable data*/
nr_lines = ZocString("LINECOUNT", data)

/* Open output file for writing */
output_file = "my_zoc_session.txt"
call lineout output_file, , 1

do i=1 to nr_lines
  /* get i-th line from the variable data */
  line = ZocString("LINE", data, i)
  /* write line to output file */
  call lineout output_file, line

/* close output file */
call lineout output_file 

If you need an example how you can read from a file and write into a file, you can look on an example I posted in this forum https://www.tek-tips.com/viewthread.cfm?qid=164026...

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close