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 11-26-2007, 09:19 AM
tatster tatster is offline
Registered User
 
Join Date: Aug 2006
Posts: 10
Send a message via MSN to tatster
waitforstrings watching for output over two lines

Hi,

I am trying to use the waitforstrings option within a script and I need a little bit of advice.

The screen output I am trying to watch for is:
Code:
User Access Verification

Username:
I have put that in text editor and can see that there is a CR, LF followed by another CR, LF between lines before the Username

This is the code I currently have that is not working....

Code:
				tacacsresult = crt.screen.WaitForStrings("assword:", "Fallback_Username:", "User Access Verification" & chr(13) & chr(10) & chr(13) & chr(10) & "Username:", "Username" ,10)
				MsgBox tacacsresult
Please can someone suggest why this isn't working ??

Many thanks,

Anthony
Reply With Quote
  #2  
Old 11-26-2007, 06:06 PM
jjh jjh is offline
VanDyke Customer Support
 
Join Date: Feb 2004
Posts: 807
Hello Anthony.

It looks like you are wanting to wait for one of the
following four strings:

"assword:"
or
"Fallback_Username:"
or
"User Access Verification" & chr(13) & chr(10) & chr(13) &
chr(10) & "Username:" or
"Username"

Is that correct?

If it is, you'll probably need to make some changes for the
last string especially. Two of the other strings you are
waiting for include the word "username" and the last string
you are waiting for is only the word "username", which could
probably cause problems.

Would you be able to describe in more detail what strings
you want to wait for and what you would like to do as a
result of finding any of them?

Because your message may contain sensitive data that you
might not want to post to a public forum, please send it via
e-mail to Support@vandyke.com.

It might also be helpful if you could provide a copy of your
entire script.

Thank you
JJH
Reply With Quote
  #3  
Old 11-27-2007, 03:35 AM
tatster tatster is offline
Registered User
 
Join Date: Aug 2006
Posts: 10
Send a message via MSN to tatster
Hi

Thanks for your reply.
The goal of my script is to connect to a number of cisco devices, and then run a few show commands on each device, while capturing the output to a log file locally per device.
The piece I am struggling with is detecting which sort of devices we connect to and then sending the correct login syntax to that device.

Here are the outputs from the 4 types of device I am trying to connect to:
Regular Telnet:
<snip>
If you are not an authorised user you are violating the regulations of
this system and can, and will be prosecuted to the full extent of the
law. Please disconnect immediately.


User Access Verification

Password: xxxxxxxx
Devicename>


Fallback tacacs:
<snip>
If you are not an authorised user you are violating the regulations of
this system and can, and will be prosecuted to the full extent of the
law. Please disconnect immediately.


User Access Verification

Fallback_Username:xxxxxxx
Fallback_Passwd:xxxxxxxx

DEVICENAME#


CSS
Escape character is '^]'.

User Access Verification

Username:xxxxxx
Password:xxxxxx
devicename#


Tacacs:
<snip>
If you are not an authorised user you are violating the regulations of
this system and can, and will be prosecuted to the full extent of the
law. Please disconnect immediately.

Username: xxxxxxxx
Password: xxxxxxxx

DEVICENAME#

Below is the Sub that is causing me headaches!!! It works fine if I am only trying 3 types of devices, it's when I added the 4 type, CSS, that I'm struggling with.

I hope this makes sense!!!!

Thanks in advance,

Anthony

Code:
Sub Main	
	Dim SwitchIP, Tempfile, section, tacacsresult
	objse.Log False
	Set SwitchIP = FSO.opentextfile(""&mydocs&"" & ""&Logfiles&"" & "\nhs_export.csv",ForReading,False)
	'Connect to Management Station
	objse.Connect "/telnet xxxxx.xxxx.xxxx.xxx.xxx 23"
	'Watch for Mgmt Station Login Prompt
	crt.Screen.WaitForString "ogin:"
	crt.Screen.Send ""&msdu8username&"" & vbCr
	crt.Screen.WaitForString "assword:"
	crt.Screen.Send ""&msdu8password&"" & vbCr
	crt.Screen.Synchronous = False
	'Wait for $ to know that we are logged on to Mgmt station correctly
	crt.Screen.WaitForString "$"
	'Start loop to read through each line of csv file containing IP's of devices to connect to
	Do While SwitchIP.AtEndOfStream <> True
		line2 = SwitchIP.ReadLine
		line2_array = Split(line2,",")
		component = line2_array(0)
		section = line2_array(1)
		mgmt_ip = line2_array(2)
		IP = mgmt_ip
			On Error Resume Next
			' Connect on from Mgmt station to device
			crt.Screen.Send "telnet "&IP&"" &vbCr
			' Look for strings to determine what sort of device we have connected to, to know how to login
				tacacsresult = crt.screen.WaitForStrings ("assword:", "Fallback_Username:", "User Access Verification" & chr(10) & chr(10) & "Username:", "Username" ,10)
				MsgBox tacacsresult
				If tacacsresult = 0 Then ' Couldn't connect
					Set Tempfile = FSO.OpenTextFile(""&mydocs&"" & ""&Logfiles&"" & "\NoConnect.txt",ForAppending, True)
					Dim whattimeisit
					whattimeisit = (now)
					Tempfile.writeline "NHS - Could Not Connect to " & IP & " at " & whattimeisit 
					Tempfile.Close()
					crt.Screen.Send Control("C") & vbCr
				End If
				If tacacsresult = 1 Then ' Regular telnet
					objSc.Send ""&telnet_passwd&"" & vbCr 
					crt.Screen.WaitForString ">"
					objSc.Send "en" & vbCr & vbCr
					crt.Screen.WaitForString "assword:"
					objSc.Send ""&enable_passwd&"" & vbCr & vbCr
					crt.Screen.WaitForString "#"
					call Capture(IP, Logfiles, mydocs)
				End If
				If tacacsresult = 2 Then ' Fallback Tacacs
					objSc.Send "xxxxxxx" & vbCr 
					crt.Screen.WaitForString "asswd:"
					crt.Screen.Send "xxxxxxx" & vbCr
					crt.Screen.WaitForString "#"
					call Capture(IP, Logfiles, mydocs)
				End If
				If tacacsresult = 3 Then ' CSS
					crt.Screen.WaitForString "Username:"
					objSc.Send "xxxxxxx" & vbCr 
					crt.Screen.WaitForString "assword:"
					crt.Screen.Send "xxxxxxx" & vbCr
					crt.Screen.WaitForString "#"
					call Capture(IP, Logfiles, mydocs)
				End If
				If tacacsresult = 4 Then ' Regular Tacacs
					objSc.Send ""&tacacs_username&"" & vbCr 
					crt.Screen.WaitForString "assword:"
					crt.Screen.Send ""&tacacs_password&"" & vbCr
					crt.Screen.WaitForString "#"
					call Capture(IP, Logfiles, mydocs)
				End If
	Loop
Reply With Quote
  #4  
Old 11-27-2007, 11:33 AM
jjh jjh is offline
VanDyke Customer Support
 
Join Date: Feb 2004
Posts: 807
Hi Anthony.

Thanks for providing that information. Based on what I see
there, it looks like you need to wait for the following
unique things:

"Password:"
"Fallback_Username:"
"Escape character is"
"Username:"

So you might change your script to look something like this:

Code:
Set objTab = crt.GetScriptTab
nResult = objTab.Screen.WaitForStrings ( _
"Password:", _ "Fallback_Username:", _ "Escape character is", _ "Username:", _ 60)
Select Case (nResult)
case 0
msgbox "Timed out waiting for a machine type indicator"
case 1
' Telnet case ' send password objTab.Screen.Send szPassword ' wait for Devicename> or even just > by itself' objTab.Screen.WaitForString ">" ' ...etc.
case 2
' Fallback_Tacacs case ' Send Fallback Username objTab.Screen.Send szFallbackUsername ' Wait for Fallback_Passwd prompt objTab.Screen.WaitForString "Fallback_Passwd:" ' Send fallback password objTab.Screen.Send szFallbackPasswd ' Wait for indication of successful login (#) objTab.Screen.WaitForString "#" '... Etc.
case 3
' . ' . ' .
' ...Etc.
end Select ' . ' . ' ... Etc.
Does that work for you?

Thanks

JJH

Last edited by jdev; 11-27-2007 at 12:01 PM.
Reply With Quote
  #5  
Old 11-28-2007, 02:37 AM
tatster tatster is offline
Registered User
 
Join Date: Aug 2006
Posts: 10
Send a message via MSN to tatster
Thanks for the reply.

Unfortunately watching for "Escape character is" won't work in this scenario as each device returns that string. It just appears before the beginning of our disclaimer text which I didn't include the whole of, in an effort to keep the post from being too long.

What I thought I could do is watch for the exact string of....

"User Access Verification

Username:"

which only appears on the 4th type of device, a Cisco CSS.

This is the bit that I'm struggling to get the script to spot that.
Reply With Quote
  #6  
Old 11-28-2007, 12:25 PM
jjh jjh is offline
VanDyke Customer Support
 
Join Date: Feb 2004
Posts: 807
You might try doing a crt.screen.waitforstring to wait for
"Escape character is", then do a crt.screen.waitforstrings
to wait for a string that is unique from each other "Escape
character is" string.

Otherwise, you might want to take a look at a raw log to see
if you can be sure that the CR's and LF's are the only
characters that you need to wait for. When you copy and
paste the information into a text editor, you might not be
pasting exactly what was sent to SecureCRT.

JJH
Reply With Quote
  #7  
Old 12-04-2007, 09:58 AM
tatster tatster is offline
Registered User
 
Join Date: Aug 2006
Posts: 10
Send a message via MSN to tatster
Hi jjh,

Thanks for the suggestions. I ran the script through with the raw log option enabled, opened the log file and saw that what SecureCRT saw from the devices was different to what I had been using in the waitforstrings bit of code.

I've now set my script to watch from what comes back, and it is doing what I want it to do.

Thanks for you help with this.

Cheers,

Anthony
Reply With Quote
  #8  
Old 12-04-2007, 10:29 AM
jjh jjh is offline
VanDyke Customer Support
 
Join Date: Feb 2004
Posts: 807
Hi Anthony.

Thank you for letting me know. I'm glad you were able to
find the right string to wait for.

JJH
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 12:36 PM.