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!

Help with ping script.... 1

Status
Not open for further replies.

GoneHiking

Technical User
Oct 27, 2006
19
US
I'm a little stumped on this one. What I have are two files of data (multiple fields, with the second field being an IP address).

In the first file (peers.txt), I want to telnet to each of the IPs in that file. Once I telnet, I want to read through another file and ping the IPs in that file. The first time around, it works fine. When I RETURN from the subroutine, the script telnet's to the second IP, but it does not call the "pingit" subroutine the second time around (or if it does, it's not reading through the file the second time).

Do I need to "reset" the file to tell it to read from line one?

This script below is just a test file. I left out a log of the logic that tells it to send the username/password, wait for a certain prompt, etc. This part is only to test and make sure it will telnet to an IP, ping a list of IPs, telnet to the next IP, and ping that same list of IPs. Hope this makes sense LOL.

Thanks,

Andy



peerfile = "c:\peers.txt"

DO WHILE (lines(peerfile) )
data=LINEIN(peerfile)
Parse Var data v1 v2 v3
testchar = RIGHT(v2,1) /* grab right-most character of field 2 */
isnum = DATATYPE(testchar) /* identify what datatype the last character is */
IF isnum = "NUM" THEN DO /* if right-most char is a number, then ping that IP */
SAY "telnet " v2 "^M"
/* ZocWait "Username:"
SAY uname
ZocWait "Password:
SAY pass
ZocWait "#" */
CALL pingit
; END
ELSE DO
NOP ; END
END
ZocSend "^M"

pingit:
pingfile = "c:\interfaces.txt"
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 field 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 */
SAY "ping" v2 "^M" ; END
ELSE DO
NOP ; END
END
RETURN
 
I did a little more testing and discovered that during the second call to the pingit subroutine, the script was not starting at line one of the "interfaces.txt" file.

So, how do I "reinitialize" that file so that it starts at line 1, no matter how many times the script calls it/reads it?

Thanks,

Andy
 
If you are using Linein() to read your file then you need to reset the read position, as stated in the manual. This is done by setting the second parameter to 1...

my_line = linein(myfile,1)
 
Of course, it seems a waste of time and resource to re-read your file every time. Why not read it once into a stem then you can iterate over it from 1 TO stem_name.0 each time? I have had stem variables with over 30,000 entries in programs.
 
nclouston, I should have mentioned I tried your first suggestion with no change in the output. I'll look into your second suggestion and see if I can't get it working that way.

Thanks,

Andy
 
nclouston, stem variables were exactly what I needed. That solved my problem. Everything "seems" to working now, but I have to test my script "for real" now. I've just been making sure it did what I wanted it to do since I didn't have access to a router.

Thanks for you help on this one. Very cool programming tool.

Andy
 
Got everything going and it works like a champ. Thanks for all of your help.

Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top