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

Need help pulling data from a text file. 1

Status
Not open for further replies.

atascoman

Technical User
Oct 10, 2003
868
US
Hello, I am trying to write a script that will be used in doing basic database changes in a wireless controller. THe goal is to have the script pull the info for each access point from the text file and reprovision them with that data. The engineers are currently having to manually enter this data into the controller for each AP and it takes forever....

I am using Secure CRT for the console interface to the controller. Here is the basic script I recorded from that application. How would I have the script pull data from a text file called APData.txt for example and then keep looping until the end of file.

The items that would be in the data file would be the ip address, Ap name and syslocation info. In the example below the ap-name field would be where "Scripted 2" appears and the syslocation field would be where "SNMP loc 2" is.

crt.Screen.Synchronous = True

' This automatically generated script may need to be
' edited in order to work correctly.

Sub Main
crt.Screen.Send "con t" & chr(13)
crt.Screen.WaitForString "(WPAruba200) (config) #"
crt.Screen.Send "provision-ap" & chr(13)
crt.Screen.WaitForString "(WPAruba200) (AP provisioning) #"
crt.Screen.Send "read-bootinfo ip-addr 192.168.0.254" & chr(13)
crt.Screen.WaitForString "(WPAruba200) (AP provisioning) #"
crt.Screen.Send "provision-ap copy-provisioning-params ip-addr 192.168.0.254" & chr(13)
crt.Screen.WaitForString "(WPAruba200) (config) #"
crt.Screen.Send "provision-ap ap-name " & chr(34) & "Scripted 2" & chr(34) & chr(13)
crt.Screen.WaitForString "(WPAruba200) (config) #"
crt.Screen.Send "provision-ap syslocation " & chr(34) & "SNMP loc 2" & chr(34) & chr(13)
crt.Screen.WaitForString "(WPAruba200) (config) #"
crt.Screen.Send "provision-ap reprovision ip-addr 192.168.0.254" & chr(13)
crt.Screen.WaitForString "(WPAruba200) (config) #"
crt.Screen.Send "exit" & chr(13)
End Sub

 
Thanks for the link. That helps a lot. I;m still not sure how to associate the information in the text file with the specific fields in my script. Do I need to use the Dim statement and create variables for the Ip Address, AP name and Syslocation info to be associated with.

Then would I change the line in the script where I want to insert the data to something like this?

crt.Screen.Send "provision-ap ap-name " & chr(34) & "APName" & chr(34) & chr(13

 
You've to decide _how_ do you store the data in the text file. It can't simply reason in the air without a convention. How about a csv file, for instance?
 
The source data will be a CSV or tab delimited text file that I want to extract from.
 
In what format and which column for which exactly then?
 
Tab delimited. Column 1 would be IP address, 2 would be AP name and 3 would be syslocation.
 
A starting point:
Code:
...
Do While f.AtEndOfStream <> True
     a = Split(f.Readline, Chr(9))
     IPaddress = a(0)
     APname = a(1)
     syslocation = a(2)     
     crt.Screen.Send ...
     ...
Loop
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
OK, I was able to get a working script. Here is what I have, it works except it doesn't like the objFSO.Close for some reason.

Dim objFSO, sInFile, oInFile, sText, arrFields
Dim sAPMAC, sAPname, sAPIPAdd, sAPmask, sAPGw, sAPDNS, sAPDomain

Sub Main

Set objFSO = CreateObject("Scripting.FileSystemObject")
sInFile = "c:\TFTProot\APPrep.txt"


If objFSO.FileExists(sInfile) Then
Set oInFile = objFSO.OpenTextFile(sInFile, 1)

Do While Not oInFile.AtEndOfStream sText = oInFile.ReadLine

arrFields = Split(sText, vbTab)
sAPMAC = arrFields(0)

sAPname = arrFields(1)


sAPIPAdd = arrFields(2)
sAPmask = arrFields(3)
sAPGw = arrFields(4)
sAPDNS = arrFields(5)
sAPDomain = arrFields(6)
sAPnewname = arrFields(7)
sAPGroup = arrFields(8)

crt.Screen.Send chr(13)
crt.Screen.WaitForString "(178alc01) (config) #"
crt.Screen.Send "provision-ap" & chr(13)
crt.Screen.WaitForString "(178alc01) (AP provisioning) #"
crt.Screen.Send "read-bootinfo wired-mac " & SAPMAC & chr(13)
crt.Screen.WaitForString "(178alc01) (AP provisioning) #"
crt.Screen.Send "provision-ap copy-provisioning-params ap-name " & sAPname & chr(13)
crt.Screen.WaitForString "(178alc01) (config) #"
crt.Screen.Send "provision-ap ipaddr " & sAPIPAdd & chr(13)
crt.Screen.WaitForString "(178alc01) (config) #"
crt.Screen.Send "provision-ap netmask " & sAPmask & chr(13)
crt.Screen.WaitForString "(178alc01) (config) #"
crt.Screen.Send "provision-ap gateway " & sAPGw & chr(13)
crt.Screen.WaitForString "(178alc01) (config) #"
crt.Screen.Send "provision-ap dns-server-ip " & sAPDNS & chr(13)
crt.Screen.WaitForString "(178alc01) (config) #"
crt.Screen.Send "provision-ap domain-name " & sAPDomain & chr(13)
crt.Screen.WaitForString "(178alc01) (config) #"
crt.Screen.Send "provision-ap ap-name " & sAPnewname & chr(13)
crt.Screen.WaitForString "(178alc01) (config) #"
crt.Screen.Send "provision-ap ap-group " & sAPGroup & chr(13)
crt.Screen.WaitForString "(178alc01) (config) #"
crt.Screen.Send "provision-ap reprovision wired-mac " & sAPMAC & chr(13)
crt.Screen.WaitForString "(178alc01) (config) #"
Loop

oInFile.Close

Else

Wscript.Echo "No input file found."

End If


objFSO.Close

End Sub
 
objFSO is not a file, it is the file system object - you do not need to 'close' it (and in fact you cannot 'close' it, as you have seen). Instead try "set objFSO = nothing".
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top