Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ZOC REXX how to send server output to file 2

Status
Not open for further replies.

lopes1211

Technical User
Jan 11, 2002
2,835
0
36
US
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?

/*REXX*/

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

file = "c:\input\ipList.txt"
do while( lines(file) )
data=LINEIN(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"
SLEEP 2
Call ZocSend "pwd^M" [highlight #FCE94F]<--- How to send this output to a file appending every time through the loop[/highlight]
SLEEP 2
Call ZocSend "exit^M"


END
EXIT

-CL
 
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.
 
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.

-CL
 
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 at ZOC REXX Reference and the examples from ZocScriptingSamples.zip e.g. these examples
03_command_answer_alternative_1.zrx
22_ParseLongCommandOutput.zrx
 
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
SLEEP 1
Call ZocSend "show image ver^M"
Call ZocWait "#"
output= ZocReceiveBuf(512)
LINEOUT(outfile,output)

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!!!!!




-CL
 
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:
Code:
/* 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
end

/* close output file */
call lineout output_file

P.S.:
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
 
Hi I do it some times for collecting info from PABX's and just use the logging so with v1 as your Server name you could just add the below around your pwd and get a file for each server


ZocLogname "C:\dir you want it in\"v1".LOG"
CALL ZocLogging 1,1

Call ZocSend "pwd^M"

CALL ZocLogging 0,1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top