Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 05-21-2013, 03:10 PM
gunslingor gunslingor is offline
Registered User
 
Join Date: May 2013
Posts: 27
problem combining command strings

Code:
	'For i=0 to narray_count
		current_interface = sinterface(0,5)
		command = "show interface " & current_interface & " | include address" & chr(13)
		msgbox command
		crt.Screen.Send command
		crt.Screen.WaitForString szStartString
Looks pretty simple right... I have an array filled with interface data. (0,X) are the interface names and (1,x) are the interface IP addressess... next I'm trying to add the MAC addresses to (2,x). The first step to is to display the MAC addresses for each interface and I've determined the best command to be "show interface [name] | include address"... I need to do this for each interface so the command should be the same, but replace [name] with the array and cycle all elements in the array (0,x).

But no matter how I try to do it, without fail... it always executes the command "show interface". It tends to show the first interface, then the command prompt is displayed with the remainder of the original command... e.g.--> some sensitive info has been redacted

Quote:
hostname>show interface
Vlan13 is administratively down, line protocol is down
Hardware is EtherSVI, address is 2222.2222.2222(bia 2222.2222.2222)
MTU 1500 bytes, BW 1000000 Kbit, DLY 10 usec,
reliability 255/255, txload 1/255, rxload 1/255
Encapsulation ARPA, loopback not set
Keepalive not supported
ARP type: ARPA, ARP Timeout 04:00:00
Last input never, output never, output hang never
Last clearing of "show interface" counters never
Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0
Queueing strategy: fifo
Output queue: 0/40 (size/max)
5 minute input rate 0 bits/sec, 0 packets/sec
5 minute output rate 0 bits/sec, 0 packets/sec
0 packets input, 0 bytes, 0 no buffer
Received 0 broadcasts (0 IP multicasts)
0 runts, 0 giants, 0 throttles
0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
0 packets output, 0 bytes, 0 underruns
0 output errors, 1 interface resets
0 output buffer failures, 0 output buffers swapped out
Vlan10000 is up, line protocol is down
Hardware is EtherSVI, address is 1111.1111.1111(bia 1111.1111.1111)

R-sw>igabitEthernet1/0/3 | include address
^
% Invalid input detected at '^' marker.
I double checked and there is no carriage return in the array. It's like VBscript can combinie strings, but then when you use the secureCRT function send, it gets hosed up. Here's the full code that you probably don't need:
Code:
Language="VBScript"
Interface="1.0"

Sub Main()

	Dim objTab
	Dim szStartString, szEndingString, szResult, icount
	Dim sversion, simage_file, smodel, sinterface(7,200)
	crt.Screen.Synchronous = True
	
	Set objTab = crt.GetScriptTab
	
	If Not objTab.session.connected then
        MsgBox "Not Connected.  Please connect before running this script."
        exit sub
    end if
	
	'determine prompt value
	szStartString = "hostname>"
	szEndingString = "hostname>"
	more_prompt = "--More--"
	'exit sub
	
	Dim n_string_start, n_string_end
	
	'pull out the OS version
	crt.Screen.Send "show version | include Cisco IOS Software"
	crt.Screen.Send chr(13)
	szResult = objTab.Screen.ReadString(szEndingString)
	n_string_start = instr(1,szResult, "Version")+8
	n_string_end = instr(n_string_start, szResult, ", ")
	sverion = mid(szResult, n_string_start, n_string_end - n_string_start)
	
	'pull out the image file name
	crt.Screen.Send "show version | include flash:/"
	crt.Screen.Send chr(13)
	szResult = objTab.Screen.ReadString(szEndingString)
	n_string_start = instrrev(szResult, chr(47))+1
	n_string_end = instrrev(szResult, chr(34))
	simage_file = mid(szResult, n_string_start, n_string_end - n_string_start)	
	
	'pull out Model #, long version
	crt.Screen.Send "show version | include Model number"
	crt.Screen.Send chr(13)
	szResult = objTab.Screen.ReadString(szEndingString)
	n_string_start = instrrev(szResult,": ")+2
	n_string_end = instrrev(szResult, chr(13))
	smodel = mid(szResult, n_string_start,n_string_end - n_string_start)
	
	'pull out interface names and IP address data
	crt.Screen.Send "show ip interface brief"
	crt.Screen.Send chr(13)
	szResult = readfull(more_prompt,szStartString)
	n_string_start = instr(1, szResult, chr(13))+1
	narray_count = 0
	do while icount < len(szResult)-1
		n_string_start = instr(n_string_start, szResult, chr(13))+1
		n_string_end = instr(n_string_start, szResult, " ")
		sinterface(0,narray_count) = mid(szResult, n_string_start,n_string_end - n_string_start)
		do
			find_IP = mid (szResult, n_string_end, 1)
			if (find_IP=" ") then
				n_string_end = n_string_end+1
			else
				exit do
			end if
		loop
		n_string_start = n_string_end
		n_string_end = instr(n_string_start, szResult, " ")
		sinterface(1,narray_count) = mid(szResult, n_string_start,n_string_end - n_string_start)
		'msgbox sinterface(0, narray_count) & ", " & sinterface(1, narray_count)
		icount = instr(n_string_end, szResult, chr(13))
		narray_count = narray_count+1
		'msgbox (sinterface & chr(13) & len(szResult) & chr(13) & icount)
	loop
	
	'grab MAC addresses
	'For i=0 to narray_count
		current_interface = sinterface(0,5)
		command = "show interface " & current_interface & " | include address" & chr(13)
		msgbox command
		crt.Screen.Send command
		crt.Screen.WaitForString szStartString
	'next
	
	'develop write string
	wstring = szStartString & vbnewline
	wstring = wstring & "OS=" & sverion & vbnewline
	wstring = wstring & "IMAGE=" & simage_file & vbnewline
	wstring = wstring & "MODEL=" & smodel & vbnewline & vbnewline
	wstring = wstring & "INTERFACES" & vbnewline
	for i=0 to narray_count 
		wstring = wstring & sinterface(0,i) & "," & sinterface(1,i) & vbnewline
	next
	
	call WriteFileText("\\serverpath", wstring)
	'test display for results
	msgbox (sverion & chr(13) & simage_file & chr(13) & smodel)
	
	'crt.Session.Disconnect
End sub

Function ReadFull(more,prompt)
	strCompleteOutput=""
	Do
		' Capture the result into a script variable.
		' Have ReadString() return after it sees one of the
		' supplied strings "pixfirewall#" or the
		' "...More..." tag.
		strResult=crt.Screen.ReadString(more,prompt)
		' Append the results we've got so far to the complete
		' results that are being accumulated.
		strCompleteOutput = strCompleteOutput & strResult
		' If a "More" was found, send a space to get the next
		' page of output from the remote
		If crt.Screen.MatchIndex = 1 Then
			crt.Screen.Send " "
		end if
		' If the shell prompt was found, then we've received
		' all of the output expected to have been sent from
		' the remote.
		If crt.Screen.MatchIndex = 2 Then 
			Exit Do
		end if
	Loop
	' A Cisco PIX sends each line followed by a line feed (LF)
	' and a Carriage return (CR). Take care of each line that
	' would have had "<--- More --->" on it. Depending on the way
	' your device tries to "erase" the "<--- More --->" prompt, you
	' may need to change the replace string below.
	strCompleteOutput = Replace(strCompleteOutput, "  " & chr(8) & chr(8) & chr(8) & chr(8) & chr(8) & chr(8) & chr(8) & chr(8) & chr(8) & "        " & chr(8) & chr(8) & chr(8) & chr(8) & chr(8) & chr(8) & chr(8) & chr(8) & chr(8), "")
	ReadFull = strCompleteOutput 
end function

Function WriteFileText(sFilePath, sText)
    Dim objFSO 'As FileSystemObject
    Dim objTextFile 'As Object
   
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTextFile = objFSO.CreateTextFile(sFilePath, True)
   
    ' Write a line.
    objTextFile.Write (sText)

    objTextFile.Close
    'objTextFile.Close

End Function

Last edited by gunslingor; 05-21-2013 at 03:14 PM.
Reply With Quote
  #2  
Old 05-21-2013, 03:27 PM
gunslingor gunslingor is offline
Registered User
 
Join Date: May 2013
Posts: 27
Alright, nevermind...lol...sorry.... apparently there is a carriage return before each element in the array. It is odd though. MS notepad seems to completely ignore any chr(13)s that are outputted to a text file... that's why I thought there were no carriage returns at first. notepad does appear to recognize vbnewline. Moderator may delete thread, your choice.

Last edited by gunslingor; 05-22-2013 at 06:34 AM.
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 12:50 PM.