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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending a carriage return - ping script... 2

Status
Not open for further replies.

GoneHiking

Technical User
Oct 27, 2006
19
US
I'm writing a script to ping a series of IP addresses and I've got all the logic in place except one piece. At the very end. I'm telling it to ping the IP, but how can I also tell it to send a carriage return (^M) at the end? I tried just a ^M at the end but go an error.

Is there some way to enclose the whole statement, but somehow tell it to interpret ^M as a carriage return, and not a literal ^ and M?

Thanks,

Andy

***********************************************
Sample of raw data
Ethernet0 12.108.00.5 YES NVRAM up up
Loopback0 12.108.200.5 YES NVRAM up up
Serial0 12.108.100.5 YES NVRAM up up
*************************************************

***************************************
This is what "myoutput.txt" looks like:

12.108.00.5
12.108.200.5
12.108.100.5
****************************************
/* Rexx */
ZocCLS
file = "c:\data.txt" -- raw data from router
outfile = "c:\myoutput.txt" --store IP address from raw data
CALL ZocFileDelete outfile --reset file for re-use

do while( lines(file) )
data=LINEIN(file)
PARSE Var data v1 v2 v3 --need second field of raw
--data, so need three variables
call lineout outfile, v2 --send field2 (the IP) of
--raw data to "outfile"
end

peers = "c:\myoutput.txt"
do while( lines(peers) ) --read in IP's from "outfile"
data=LINEIN(peers) --continue reading until no more lines
PARSE Var data v1 --grab field1 (there's only one field)
SAY "ping " v1 --ping each IP
end
 
In your script you didn't execute ping command, you only typed it on the screen with
Code:
SAY "ping " v1 --ping each IP

If your variable v1 contains the IP-address, for example
Code:
v1 = '12.108.100.5'
then you can ping it with
Code:
ping_command = 'ping' v1
say 'Executing :' ping_command
/* Now execute the command */
ping_command

My question is, why you are first reading and parsing the raw data file, then writing the second column in other file. And then reading this other file and pinging the address. IMHO, you can ping the adress after reading the line from raw data file...
 
MikeRom, that's a good point. I just wasn't thinking it through. I have incorporated that into my script. Thanks for pointing that out.

I have one small issue. I've got it working, but in the last piece of the script, every time it sends the ping command, that statement is preceded by "+++ RC=2 +++". Here's a snippet (hostname and IP replaced for security purposes):

hostname# *-* ESLE DO
+++ RC=2 +++
ping x.x.x.x

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to x.x.x.x, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 44/44/48 ms

hostname# *-* ESLE DO
+++ RC=2 +++
ping x.x.x.x

etc.
=================

Here's the chunk of code in question:

pingfile = "c:\interfaces.txt"
CALL ZocFileDelete outfile

DO WHILE ( lines(pingfile) )
data=LINEIN(pingfile)
Parse Var data v1 v2 v3
call lineout outfile, v2
letter = RIGHT(v2,1) -- grab right-most character of fiedl 2
isnum = DATATYPE(letter) -- identify what datatype the last character is

IF isnum = "NUM" THEN DO -- if right-most char is a number, then ping that IP
ZocSend "ping" v2 "^M"
ZocWait "#" ; END
ESLE DO
NOP
END
ZocSend "^M"
 
Never mind. I see what I did. I mis-spelled ELSE as ESLE :(

 
To avoid typos use an editor with syntax highlighting.

Concerning Carriage Return and other control characters:
You can use hex codes - see example
Code:
CR = '0D'X /* ASCII Enter i.e. Carriage Return */
LF = '0A'X /* ASCII Line Feed */    
BS = '08'X /* ASCII BackSpace */
BEL= '07'X /* ASCII Beep sound */ 

hello = 'Hello World'
say hello||BEL||LF||LF||hello||BEL

 
mikrom, thanks for the additional info. Can you recommend a good editor that does syntax highlighting? I'm currently using Notepad++ (which supports languages such as python and perl, but unfortunately, not Rexx).

Thanks,

Andy
 
I use Textpad - you can highlight any language any way you want as you create the syntax file. But for Rexx, and lots of other languages, you can download a file from the Textpad site.
 
Thanks nclouston. That program looks promising. I downloaded the rexx.syn file and got it going.

Andy
 
I'm using Vim. It comes by default with syntaxhighlighting for REXX and other languages.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top