Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 06-23-2013, 07:09 AM
banksbc banksbc is offline
Registered User
 
Join Date: Mar 2011
Posts: 3
Script keeps hanging

I am running a vbscript that crawls my network devices based on a .csv, runs a few commands, disconnects, opens a new tab and a starts a new connection. The problem I am having is that for some reason it hangs and I have to hit <Enter> for the script to resume.
Reply With Quote
  #2  
Old 06-24-2013, 07:31 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi banksbc,

Thanks for the post. What version of SecureCRT are you using?

At what point in the script do you see the hang?

You can determine this by cancelling the script when it is hanging (Script / Cancel).

Would you post the script you are using?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #3  
Old 06-25-2013, 10:33 AM
banksbc banksbc is offline
Registered User
 
Join Date: Mar 2011
Posts: 3
I figured out my problem. I use an SSH proxy that gets bogged down and enter wasn't necessarily fixing anything as much as simply waiting for the proxy to catch up. That said I am now bypassing my proxy and going directly to the device. My problem now is that the script seems to be running to fast for secure crt to keep up. It will skip a waitforstring and go to the next line of code causing the whole thing to break.

Please keep in mind I am very novice in the world of scripting:

Here is the script I am trying to run:
Code:
# $language = "VBScript"
# $interface = "1.0"


Dim g_fso, g_shell
Set g_fso = CreateObject("Scripting.FileSystemObject")
Set g_shell = CreateObject("WScript.Shell")

'Network Devices need to be .csv format and stored in My Documents\Scripts\Hosts.csv
g_strHostsFile = g_shell.SpecialFolders("MyDocuments") & "\Scripts\Hosts.csv"
g_strComment = "#"

crt.Screen.Synchronous = True

Sub Main
	Dim line
	Dim cnxnString
	Dim g_nMode
	Dim strHostname
	Dim vLines()
	Dim nLineCount, nCommentLines


	strUsername = 	crt.dialog.Prompt(_
			"What is your username? ","Username",,False)
	strPassword = 	crt.dialog.Prompt(_
			"What is your password? ","Password",,True)

	If Not ReadDataFromFile(g_strHostsFile, _
				g_strComment, _
				vLines, _
				nLineCount, _
				nCommentLines) Then
		MsgBox "No lines were found in file: " & vbcrlf & vbtab & g_strDataFile
		Exit Sub
	End If
	' Iterate through each element of our vLines array and connect
	
	For nIndex = 1 To nLineCount
			' Arrays are indexed at zero...
			strIP = vLines(nIndex - 1)


		cnxnString = ("/SSH2 /P 22 /L " & strUsername & " /password " & strPassword & " /ACCEPTHOSTKEYS " & strIP)
		'
		Set newTab = crt.session.ConnectInTab(cnxnString)
		newTab.Activate
		newTab.caption=strIP

		'Need to get rid of any old banners that exist
		newTab.Screen.Send "show run | i banner" & vbCr
		newTab.Screen.WaitForString "banner", 10
		strBanner = newTab.Screen.ReadString("SSH")
		aryBanner = Split(strBanner,vbCr)
		newTab.Screen.Send "conf t" & vbCr
		newTab.Screen.WaitForString "(config)#", 5
		For Each strBannerExist in aryBanner
			Do
				strLen = Len(strBannerExist)
				If strLen < 4 Then Exit Do
				strBannerExist = Trim(strBannerExist)
				strBannerExist = Left(strBannerExist,strLen - 3)
				strBannerExist = Replace(strBannerExist,vblf,"")
				newTab.Screen.WaitForString "#", 5
				If strBannerExist <> "" Then
					newTab.Screen.Send "No " & strBannerExist & vbCr
				End If
			Loop while False
		Next
		aryNewBanner = Split("exec|motd|incoming","|")
		For Each strBannerNew in aryNewBanner
			newTab.Screen.WaitForString "(config)#", 5
			newTab.Screen.Send "banner " & strBannerNew & " x" & vbCr
			newTab.Screen.WaitForString "'x'.", 10
			newTab.Screen.Send "You are accessing a U.S. Government (USG) Information System (IS) that is provided for USG-authorized" & vbCr & _
			"use only. By using this IS (which includes any device attached to this IS), you consent to the following" & vbCr & _
			"conditions:-The USG routinely intercepts and monitors communications on this IS for purposes including," & vbCr & _
			"but not limited to, penetration testing, COMSEC monitoring, network operations and defense, personnel " & vbCr & _
			"misconduct (PM), law enforcement (LE), andcounterintelligence (CI) investigations.-At any time, the USG" & vbCr & _
			"may inspect and seize data stored on this IS.-Communications using, or data stored on, this IS are not" & vbCr & _
			"private, are subject to routine monitoring, interception, and search, and may be disclosed or used for" & vbCr & _
			"any USG-authorized purpose.-This IS includes security measures (e.g., authentication and access" & vbCr & _
			"controls) to protect USG interests--not for your personal benefit or privacy.-Notwithstanding the above," & vbCr & _
			"using this IS does not constitute consent to PM, LE or CI investigative searching or monitoring of the" & vbCr & _
			"content of privileged communications, or work product, related to personal representation or services by" & vbCr & _
			"attorneys, psychotherapists, or clergy, and their assistants. Such communications and work product are" & vbCr & _
			"private and confidential. See User Agreement for details" & vbCr & "x" & vbCr
			
		Next
		newTab.Screen.WaitForString "(config)#", 5
		newTab.Screen.Send "end" & vbCr 
		newTab.Screen.WaitForString "#", 5
		newTab.Screen.Send "exit" & vbCr
		newTab.Screen.WaitForString ">", 5
		newTab.Screen.Send "exit" & vbCr		
		newTab.Close
	Next
End Sub	
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function ReadDataFromFile(strFile, _
			strComment, _
			ByRef vLines, _
			ByRef nLineCount, _
			ByRef nCommentLines)

' Returns True if the file was found.
' strFile: IN parameter specifying full path to data file.
' strComment: IN parameter specifying string that preceded
' by 0 or more space characters will indicate
' that the line should be ignored.
' vLines: OUT parameter (destructive) containing array
' of lines read in from file.
' nLineCount: OUT parameter (destructive) indicating number
' of lines read in from file.
' nCommentLines: OUT parameter (destructive) indicating number
' of comment/blank lines found
'
'
	' Check to see if the file exists... if not, bail early.
	If Not g_fso.FileExists(strFile) Then Exit Function

	' Start off with a reasonable size for the array:
	ReDim vLines(5)

	' Open a TextStream Object to the file...
	Set objTextStream = g_fso.OpenTextFile(strFile, 1, False)

	' Used for detecting comment lines, a regular expression object
	Set re = New RegExp
	re.Pattern = "(^[ \t]*(?:" & strComment & ")+.*$)|(^[ \t]+$)|(^$)"
	re.Multiline = False
	re.IgnoreCase = False

	' Now read in each line of the file and add an element to
	' the array for each line that isn't just spaces...
	nLineCount = 0
	nCommentLines = 0

	Do While Not objTextStream.AtEndOfStream
		strLine = ""

		' Find out if we need to make our array bigger yet
		' to accommodate all the lines in the file. For large
		' files, this can be very memory-intensive.
		
		If UBound(vLines) >= nLineCount Then
			ReDim Preserve vLines(nLineCount + 5)
		End If

		strLine = Trim(objTextStream.ReadLine)

		' Look for comment lines that match the pattern
		' [whitespace][strComment]
		
		If re.Test(strLine) Then
			' Line matches our comment pattern... ignore it
			nCommentLines = nCommentLines + 1
		Else
			vLines(nLineCount) = strLine
			nLineCount = nLineCount + 1
		End If
	Loop

	objTextStream.Close

	ReadDataFromFile = True

End Function
Please help...

Last edited by rtb; 06-25-2013 at 01:46 PM.
Reply With Quote
  #4  
Old 06-25-2013, 01:53 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi banksbc,

It is hard to help when we don't have very many details. At what point does the script stop functioning as you expect?

When the script does fail, how does the whole thing break?

Does the script hang at some point?

If so, when you cancel the script, what line is indicated?

Are you certain that the string you are waiting for after sending data is unique enough that it will not appear in any of the output thus causing the script to move forward before you would expect?

What version of SecureCRT are you using?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 06:47 AM.