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!

Need my script to move on if it can't telnet to a router, and tell me.

Status
Not open for further replies.

CaliColin

Technical User
Jun 15, 2006
2
0
0
US
My script telnets to a list of routers in a text file (one by one), and issues a command to each router. The problem is, when it gets to a router that is unreachable, the script simply hangs and I have to figure out where it hung, and remove that router's IP address from the text file. Then I have to start the script again from where it left off. First, I would like the script to move on to the next router in the list, even if it gets hung up on a non-existent router. Second, it would be nice if the script could output the failures to a file that I could read later. I think I can do this with some kind of command that tells Procomm to move on to the next router if it doesn't get a response in 10 sec. or so. Not sure though. Here's what I have currently:

proc main

string szFname = "C:\routers.txt"

if fopen 0 szFname READ TEXT
while not feof 0
fgets 0 szLine

LoopbackIP = szLine
strcat LoopbackIP ".1"
connectmanual telnet LoopbackIP
waitfor "Password: "
transmit "mypwd^M"
waitfor ">"
transmit "en^M"
waitfor "Password: "
transmit "myenablepwd^M"
waitfor "#"
transmit "show ip eigrp neigh^M"
waitfor "#"
transmit "quit^M"

endwhile ;stops the loop
fclose 0 ;close the file

else
errormsg "Couldn't open c:\routers.txt !"
endif


endproc
 
If you change this line:

waitfor "Password: "

to:

if waitfor "Password: "

and add a matching endif after the transmit "quit^M" line, you can use an else clause that will handle the non-connection.

 
Cool, this seems to get me most of the way there! I incorporated your suggestion and now have this:
-------------------------------
proc main

string szFname = "C:\routers.txt"

if fopen 0 szFname READ TEXT
while not feof 0
fgets 0 szLine

LoopbackIP = szLine
strcat LoopbackIP ".1"
connectmanual telnet LoopbackIP
if waitfor "Password: "
transmit "mypwd^M"
waitfor ">"
transmit "en^M"
waitfor "Password: "
transmit "myenablepwd^M"
waitfor "#"
transmit "show ip eigrp neigh^M"
waitfor "#"
transmit "quit^M"
else errormsg "Couldn't telnet to router"
endif
endwhile ;stops the loop
fclose 0 ;close the file

else
errormsg "Couldn't open c:\routers.txt !"
endif


endproc
-------------------------------
So now on a failed router, I get a dialog box that I can acknowledge and manually document the router that failed. Is there a way for the script to keep going, but output the failed router IP address to a file?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top