ZOC REXX how to send server output to file
ZOC REXX how to send server output to file
(OP)
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" <--- How to send this output to a file appending every time through the loop
SLEEP 2
Call ZocSend "exit^M"
END
EXIT
-CL
/*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" <--- How to send this output to a file appending every time through the loop
SLEEP 2
Call ZocSend "exit^M"
END
EXIT
-CL
RE: ZOC REXX how to send server output to file
Frank Clarke
--America's source for adverse opinions since 1943.
RE: ZOC REXX how to send server output to file
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
RE: ZOC REXX how to send server output to file
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
03_command_answer_alternative_1.zrx
22_ParseLongCommandOutput.zrx
RE: ZOC REXX how to send server output to file
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
RE: ZOC REXX how to send server output to file
I don't know ZOC, but I would try to do something like this:
CODE
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 https://www.tek-tips.com/viewthread.cfm?qid=164026...