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

Updating Cisco routers. Need script to read from a separate list. 2

Status
Not open for further replies.

kayl99

Technical User
Jan 15, 2009
3
US
I have to add a logging server address to about 1000 Cisco routers. I want to use Procomm Plus and an Aspect script for this. Using the script recorder, I captured one update.

Is there a way to modify this so the script reads the routers from a separate list? Reading through the help files, it looks like there is but I am no programmer!

Any help would be appreciated.

proc main
connectmanual TELNET "ROUTER1"
waitfor "Username: "
transmit "USERNAME^M"
waitfor "Password: "
transmit "PASSWORD^M"
waitfor "ROUTER1>"
transmit "ena^M"
waitfor "Password: "
transmit "PASSWORD^M"
waitfor "ROUTER1#"
transmit "config t^M"
waitfor "ROUTER1(config)#"
transmit "logging 192.168.0.1^M"
waitfor "ROUTER1(config)#"
transmit "end^M"
waitfor "ROUTER1#"
transmit "wr^M"
waitfor "ROUTER1#"
transmit "exit^M"
endproc
 
Basically you need to wrap the "core" code of your script inside a while loop and iterate through your data source. Below is a sample script from my site that shows how to open a text file and loop through it. Your code would replace the section that starts with if not nullstr sNum and ends with an endif statement.

proc main
string sNum

if fopen 0 "numbers.txt" READ TEXT ;Open text file containing list of connections
while not feof 0 ;While data remains in the file
fgets 0 sNum ;Get entry from file
if not nullstr sNum ;If entry is not blank
dial DATA sNum ;Then dial it
while $DIALING ;Pause while dialing
yield
endwhile
if $CARRIER ;If connected...
;perform operations here once connected...
endif
endif
endwhile
endif
fclose 0 ;Close data file
endproc

It looks like you may need to pull more than one piece of data per system in the text file. If so, I would recommend using a command like strexctract so you can read the line of data using fgets, then access each "chunk" of that line as needed.

 
Knob, THANK YOU! It works like a charm! This will save me hours of time.

Here's what my script ended up looking like:

string sIP

proc main

if fopen 0 "C:\routerlist.txt" READ TEXT ;Open text file containing list of connections
while not feof 0 ;While data remains in the file
fgets 0 sIP ;Get entry from file

connectmanual TELNET sIP ;Then dial it
waitfor "Username: "
transmit "USERNAME^M"
waitfor "Password: "
transmit "PASSWORD^M"
waitfor ">"
transmit "ena^M"
waitfor "Password: "
transmit "PASSWORD^M"
waitfor "#"
transmit "config t^M"
waitfor "(config)#"
transmit "logging 192.168.0.1^M"
waitfor "(config)#"
transmit "end^M"
waitfor "#"
transmit "wr^M"
waitfor "#"
transmit "exit^M"
pause 2

endwhile
endif
fclose 0 ;Close data file
endproc


My "Routerlist.txt file is just a list:

ROUTER1
ROUTER2
ROUTER3


I added the pause because the script seemed to move to the next item too fast. The pause took care of that. I haven't tried a list longer than 3 items yet. Thought I'd start small before jumping off the cliff.
 
Knob,

Thought I'd give you an update. It worked beautifully. I owe you a beer sir!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top