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

Script with multiple input from keyboard

Status
Not open for further replies.

theonlyciscokid

IS-IT--Management
Mar 1, 2003
3
US
I neede a script to configure multiple Cisco routers for a rollout. The routers will do voice and I need to enter different numbers as I go such as the IP address for the Serial interface and the ip address for the ethernet interface. Plus the dila-peer numbers. I know how to one one input but not multiple inputs in the same script. Can someone provide a hint or a sample script.
Thanks You
 
Will the same commands be sent to each router, just the arguments to each command will be different? If so, you could write a text file that contains all of the unique data for each router, and your script could read the data for each router, send the necessary commands, and repeat while there is still data in the text file. Here is a rough prototype that you could use:

proc main
string sLine
integer iLen

fopen 0 "c:\data.txt" READ TEXT
while not feof 0
strlen sLine iLen
fgets 0 sLine ;read line of data from text file
if iLen == 0
exitwhile
endif
connectmanual telnet "ipaddress"
while $DIALING
yield
endwhile
transmit ......
transmit ......
transmit ......
disconnect
endwhile
fclose 0
endproc

The way this is written, only one line of data is needed per router, but that may not be enough for your situation (strings are limited to 255 characters in ASPECT). I would recommend making the data in the file comma-delimited so you can break up each element (IP address, password, arguments to various commands, etc.) using the strtok command. The various transmit statements in the script represent the different commands that you send to the routers.

aspect@aspectscripting.com
 
I would excel to make the text file as Knob describes above:
A B C D E
Router Ethernet Addr Ser0 IP Addr Ser1 IP Addr Dial Peer
Set E0 IP %s set S0 %s set S1 %s set peer dial %s
rtr 1 192.152.10.1 192.152.20.1 192.152.30.1 555-1212
rtr 2 192.152.20.1 192.152.10.1 192.152.30.1 555-1213
rtr 3 192.152.30.1 192.152.10.1 192.152.20.1 555-1214

Then save the Excel file as a CSV (comma separated variable) file. which will yield:

Router,Ethernet Addr,Ser0 IP Addr,Ser1 IP Addr,Dial Peer
rtr 1,192.152.10.1,192.152.20.1,192.152.30.1,555-1212
rtr 2,192.152.20.1,192.152.10.1,192.152.30.1,555-1213
rtr 1,192.152.30.1,192.152.10.1,192.152.20.1,555-1214
,Set E0 IP %s,set S0 %s,set S1 %s,set peer dial %s

proc main
string sLine, sItem, sCmds, cmd
integer iLen, cntr, Num_items

fopen 0 "c:\Rtr_data.csv" READ TEXT
fgets 0 sLine ; read the headings line from file
fgets 0 sCmds
while not feof 0
strlen sLine iLen
fgets 0 sLine ;read line of data from text file
if iLen == 0
exitwhile
endif
strextract sItem sLine "," 0 ; get the Rtr name
usermsg "Connect to the %s router craft port" sItem
; prompt you to connect your cable to the Rtr

#comment
; these lines can be substituted after the Rtrs are rolled out fro the usermsg cmd above also substituting an IP address for the router name
connectmanual telnet "ipaddress"
while $DIALING
yield
endwhile
#endcomment

strsearch sLine "," Num_items ;get the number of commas ie items in the sLine for the rtr

for cntr = 1 upto Num_Items
strextract sItem sLine "," cntr ; get next item from the line
strextract cmd sCmds "," cntr ; get cmd string for this item
strfmt cmd cmd sItem ; insert the Ip address from sItem into cmd where the %s is
transmit cmd
waitfor "prompt" 10 ;substitute the Rtr prompt for the word prompt
endfor

disconnect
endwhile
fclose 0
endproc

The one line limit per router will give you approximately 16 collumns of data with 16 characters per collumn. That is what IP addresses would max out as including the comma seperator. Telephone numbers would probably be a couple less unless you're using outside line access digits or pauses. Strtok as Knob mentioned is another way to pull data out of a delimited string but I tend to prefer strextract. Sorry if the Cisco IOS commands are way off but its been a year since I was delving into the cisco stuff.
Hope this helped. You could also add the login and setup your rollout passwords with the script as well.

DT


 
Correction the CSV will be:

Router,Ethernet Addr,Ser0 IP Addr,Ser1 IP Addr,Dial Peer
,Set E0 IP %s,set S0 %s,set S1 %s,set peer dial %s
rtr 1,192.152.10.1,192.152.20.1,192.152.30.1,555-1212
rtr 2,192.152.20.1,192.152.10.1,192.152.30.1,555-1213
rtr 1,192.152.30.1,192.152.10.1,192.152.20.1,555-1214


I put the command string line at the bottom by accident, sorry.

DT
 
I do thank everyone that answered this. Below is the script that I have and I hope that you can tell from these 3 was files what I am doing. I am connected to these routers via the console port and am configuring them on the bench. As for the script you provided I don't quite understand how to get all of the commands (cisco) into script that you provided. So to be a pain here, but if maybe you can take what I have and provide a sample I would appreciate it very much!!!

router 1.was

proc main
string szStoreNumber1
sdlginput "Freds Store Number 1" "Enter the 4 numbers of the Store Number:" szStoreNumber1
SendData( szStoreNumber1 ) ; Call the SendData routine with the value of the local

endproc

string Name = Name
proc senddata
param string szStoreNumber1

name = szStoreNumber1

call config
chain "router 2.was"

endproc

proc config

transmit "^c^M"
pause 3
transmit "^M"
waitfor "Router>"
transmit "ena^M"
transmit "config t^M"
transmit "no service password-encryption^M"
transmit "hostname Store#"
transmit Name
transmit "^M"
transmit "aaa new-model^M"
transmit "aaa authentication login default local^M"
transmit "aaa authentication login vty local^M"
transmit "aaa authentication ppp default local^M"
transmit "aaa session-id common^M"
transmit "enable secret 5 $1$5Vdw$33eVVSdlvpzSlHESgoU9o0^M"
transmit "username joe password 0 joejoe^M"
transmit "ip subnet-zero^M"
transmit "no ip domain-lookup^M"
transmit "class-map match-all CONTROL^M"
transmit " match access-group 102^M"
transmit "class-map match-all VOICE^M"
transmit " match access-group 101^M"
transmit "policy-map VOIP^M"
transmit "class VOICE^M"
transmit "priority 24^M"
transmit "class CONTROL^M"
transmit "bandwidth 8^M"
transmit "class class-default^M"
transmit "fair-queue 64^M"
transmit "random-detect^M"

endProc

router 2.was

proc main
string szStoreNumber1

sdlginput "Joes Store Number 1" "Enter the first 2 numbers of the Store Number:" szStoreNumber1
SendData( szStoreNumber1 )

endproc


string Name = Name

proc senddata

param string szStoreNumber1

name = szStoreNumber1
call config
chain "router 3.was"

endproc

proc config

transmit "fax interface-type fax-mail^M"
transmit "mta receive maximum-recipients 0^M"
transmit "interface FastEthernet0/0^M"
transmit "ip address 10."
transmit name
transmit "."

endProc


router 3.was
proc main
string szStoreNumber1
sdlginput "Freds Store Number 1" "Enter the Second 2 numbers of the Store Number:" szStoreNumber1

endproc

string Name = Name

proc senddata

param string szStoreNumber1

name = szStoreNumber1
call config
chain "router 4.was"

endproc

proc config

transmit name
transmit ".1 255.255.255.128^M"
transmit "speed auto^M"

transmit "interface Serial0/0^M"
transmit "no ip address^M"
transmit "encapsulation frame-relay^M"
transmit "frame-relay traffic-shaping^M"
pause 3
transmit "frame-relay ip rtp header-compression^M"

endProc
 
I guess the main question I have is what you are looking for when you say you want a script that uses multiple inputs. The scripts you posted don't have much in common, so I don't think a more generalized script can be written that would work for all three cases.

Basically what myself and det07 were saying is your script would read the arguments to the various transmit commands from a text file, so that all of the commands could be in one text file and you would have one script that would read a line of data from the text file, which would have the IP address to connect to and the various strings to transmit to the router. I suppose it could be possible to write on generic script that transmits strings to the router until the line (or lines) of data from the text file is exhausted.


aspect@aspectscripting.com
 
I am not entirely sure what you're trying to do either.

If I understand you are running script 1 inputting the site "XXxx" then running a set list of commands that do not have any particular variable data.
Then you start a new script to do nearly the same thing but with some differences for a second router designating its' site by inputting "XX" of a "XXxx" type of site designation then running a different list of commands.
Then you get into a third inputting "xx" of the "XXxx" site designation and running a third set of commands.

I guess what I would do is designate the site the same way with all 4 digits (as string) each time then have a command file for each "RTR_setup_XXxx" with each command listed on a line. Then all you do is SDLGinput the site "XXxx" strcat the "XXxx" onto the filename variable "RTR_setup_" open the file get a line one at a time and transmit until EOF. Put a conditional after the SDLGinput to check for a value like "EXIT" or "ZZ" and if that value is there then exit the script.

proc main

string sLine, cmd, sStoreNumber, file_nm
integer cntr, iLen, StoreNum
StoreNum = 9
while StoreNum > 0
sdlginput "Enter Store Number" "Enter the 4 numbers of the Store Number: " sStoreNumber
atoi sStoreNumber StrNum
if StoreNum == 0 ; if 0 entered for store number exit script
exitwhile
endif
strfmt file_nm "C:\RTR\RTR_setup_%s.txt" sStoreNumber
fopen 0 file_nm READ TEXT
while not FEOF 0
fgets 0 sLine
strlen sLine iLen
if iLen == 0
exitwhile
endif
transmit sLine
waitquiet 1
endwhile
endwhile
endproc

Just make a text file for each router named as such with one Cisco command per a line, ie:

ip subnet-zero^M
no ip domain-lookup^M

I hope this helped some.

DT
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top