#1
|
|||
|
|||
Variable from File likely csv
All,
I'm looking to create a script, preferring VB, that will read variables from a CSV file and insert them into the script in a loop. File content example TelnetTo,WAN1,WAN1IP,WAN2,WAN2IP,BGPNum,BGPPeer 192.168.1.1,Gi0/0/1,172.16.1.1,Gi0/0/2,172.17.1.1,123,172.16.1.2 There are about 300 rows in the document, the below is a sample and not actual IPs. Looking to have the script (once already connected to a jump server) cycle through each host in the TelnetTo column. HTML Code:
#$language = "VBScript" #$interface = "1.0" crt.Screen.Synchronous = True Sub Main Set fso = CreateObject("Scripting.FileSystemObject") Set hosts = fso.OpenTextFile("SomePath\SomeFile.csv") MyVar = Split(hosts.ReadAll, vbcrlf) hosts.Close For Each thing In MyVar crt.Screen.Send "telnet " & thing & chr(13) If crt.Screen.WaitForStrings ("NA-US-R3-JUMPsvr105#", "username: ") = 2 then crt.Screen.Send "user" & chr(13) crt.Screen.WaitForString "password: " crt.Screen.Send "pass" & chr(13) crt.Screen.WaitForString ">" crt.Screen.Send "en" & chr(13) crt.Screen.Send "pass" & chr(13) crt.Screen.WaitForString "#" crt.Screen.Send "conf t" & chr(13) crt.Screen.WaitForString "(config)#" crt.Screen.Send "interface " & thing1 & chr(13) crt.Screen.Send "ip address " & thing2 & " 255.0.0.0" & chr(13) crt.Screen.WaitForString "(config)#" crt.Screen.Send "end" & chr(13) crt.Screen.WaitForString "#" crt.Screen.Send "wr" & chr(13) crt.Screen.WaitForString "#" crt.Screen.Send "exit" & chr(13) crt.Screen.WaitForString "NA-US-R3-JUMPsvr105#" Else crt.Screen.Send chr(13) crt.Screen.WaitForString "NA-US-R3-JUMPsvr105#" End If Next End Sub |
#2
|
||||
|
||||
Here are the steps I would suggest you take to create such a script:
Also, take a look through the script examples available on the Script Examples "sticky". There are lots of examples that show techniques to perform tasks and there's code already there for the learning. For example, if you already have a spreadsheet with this information in it, there's an example of how to use the information directly from the spreadsheet to connect to a host (even from a gateway/jumphost scenario) and perform a series of commands -- see the "ExcelSpreadsheets-SearchingAndLookup-GatewayLogins" code in the Integrating with Microsoft Excel script example. --Jake
__________________
Jake Devenport VanDyke Software Technical Support YouTube Channel: https://www.youtube.com/vandykesoftware Email: support@vandyke.com Web: https://www.vandyke.com/support Last edited by jdev; 11-09-2017 at 11:28 AM. |
![]() |
Tags |
csv , vbs , vbscript |
Thread Tools | |
Display Modes | Rate This Thread |
|
|