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 07-03-2013, 05:19 AM
emailsbecker emailsbecker is offline
Registered User
 
Join Date: Apr 2011
Posts: 74
Two scripts exactly alike, but they give different results

Hi all,

I have some code that's not working right. In order to isolate possible problems I removed the offending code into its own tiny script to see what was going on, and turned on a raw log. I get a different response from the device even though the commands are exactly the same. Any advice?

Here's the small bit of code:

Code:
crt.Screen.Send "sh run | i tacacs-server host" & vbCr : crt.Screen.WaitForString vbcr
strServerResults = crt.Screen.ReadString ("#")
msgbox strServerResults
Here it is in the larger setting:

Code:
' *************************************************************
' *************************************************************
' ************************ CiscoSub ***************************
' *************************************************************
' *************************************************************

' Cisco hostname is gathered in GetEnableSub but if the script goes right into
' EXEC mode we still need to get it here
If strHostname = "" Then
	crt.Screen.Send vbCr : crt.Screen.WaitForString "#"
	crt.Screen.Send vbCr : crt.Screen.WaitForString vbCr
  strHNMpre = crt.Screen.ReadString ("#")
	' Get Hostname for ASR
	If strCPEType = "ASR" Then
 	  strHostname = trim(Split(strHNMpre, ":") (1))
  End If

	' Get Hostname for Other Cisco devices, trim leading vblf if found
	 If strCPEType = "Cisco" Then

   If instr(strHostname, chr(10)) <> 0 Then
      strHostname = Split(strHNMpre, chr(10))(1)
    End If
    If instr(strHostname, chr(10)) = 0 Then
      strHostname = strHNMpre
    End If
    If instr(strHNMpre, vblf) = 1 Then
     strHostname = split(strHNMpre, vblf)(1)
    End If
 End If
End If

' Gather info
crt.Screen.Send "sh run | i tacacs-server host" & vbCr : crt.Screen.WaitForString vbCr
strServerResults = crt.Screen.ReadString ("#")
msgbox strServerResults

If instr(strServerResults, "71.") <> 0 Then
  Call ScanServerSub
End If
msgbox strServerResults

' If the command above nets no results
If instr(strServerResults, "71.") = 0 Then
  crt.Screen.Send "sh run | i server-private" & vbCr : crt.Screen.WaitForString vbCr
  strServerResults = crt.Screen.ReadString ("#") : Call ScanServerSub
End If
msgbox strServerResults

' Exit device
crt.Screen.Send "exit" & vbCr : crt.Screen.WaitForString ("~>")
End Sub
I'll attach an edited version of the raw capture, taking out personal details. You'll notice that the script doesn't recognize the first command was successful, runs the second command. And, by the way, it takes the response from the first command and reads it as though it were the response to the second command. Any idea what's going on here? (Oh, and I do have "crt.Screen.Synchronous = True" at the top of both scripts.)

Thanks in advance.
Attached Files
File Type: txt test - RAW.txt (2.9 KB, 527 views)

Last edited by emailsbecker; 07-03-2013 at 05:28 AM.
Reply With Quote
  #2  
Old 07-03-2013, 08:36 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,305
Hi emailsbecker,

I really need more information. We have the script, and we have the raw log, but I don't know exactly how the script is failing.

Even though Synchronous is set to True, it is possible for the script to already be out of sync, so just snippets are not likely going to be enough to help.

How do the results from the small snippet of code differ from the larger setting?

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

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #3  
Old 07-08-2013, 06:35 AM
emailsbecker emailsbecker is offline
Registered User
 
Join Date: Apr 2011
Posts: 74
Todd,

Version 6.1.1 ... Oof, I see that was released in 2008. Strange, it says it's the 2008 release and support ends 2009 but I didn't start working here until 2010. I'm not positive but I think I downloaded this and installed it myself, it wasn't part of the image this computer came with. Maybe it was and I'm remembering incorrectly.

As for how the results differ from the original setting ... the smaller snippet correctly grasps the result of the "show run | i tacacs-server host" command. In the larger setting the device seems to be doing an invisible echo to every command, which includes the device name and prompt:

Code:
RP/0/RSP0/CPU0:hostname1#sh run | i tacacs-server host

RP/0/RSP0/CPU0:hostname1#sh run | i tacacs-server host
Because I use crt.Screen.ReadString ("#") the script gets the echoed command, and never sees the output.

How can SecureCRT lose sync after crt.Screen.Synchronous = True ?

Last edited by emailsbecker; 07-08-2013 at 06:39 AM.
Reply With Quote
  #4  
Old 07-08-2013, 12:03 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,305
Hi emailsbecker,

Thanks for the information. I went back and looked at the raw log you posted again, and the problem appears to be occurring before you actually see the problem in your script. Since the remote is sending the duplicate lines from the first command that is sent, this doesn't look like a problem that can be resolved in SecureCRT.

I would suggest investigating why the remote device is duplicating lines. Once you have that resolved, the next step would be to see if your script is still failing.
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #5  
Old 07-09-2013, 05:14 PM
emailsbecker emailsbecker is offline
Registered User
 
Join Date: Apr 2011
Posts: 74
Hi Todd,

I've opened a ticket with the team that maintains our bastion server, and will work with them on that end of things. However I'd like to ask that second question again - How can SecureCRT lose sync after crt.Screen.Synchronous = True ? Also, is there a way for me to check sync within the script? If so I can have it periodically check and correct it.

The reason I want to re-address that is because this error is reproducible. It clearly does not happen when I use only the short snippet of code in a testing script, and it does happen when I use it inside the longer script. So it sounds to me like there's something in my script that's causing the loss of sync.
Reply With Quote
  #6  
Old 07-10-2013, 10:07 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,305
Hi emailsbecker,

SecureCRT doesn't lose sync. Once Screen.Synchronous is set to True, it remains such until set otherwise, or until the connection or script terminates.

However, script authors may be out of sync in their approaches related to Send() and WaitFor...() when Synchronous is set to True. The best practice involves ensuring that for each command sent via Send(), there is a corresponding WaitForString-like call to stay in sync with the data that has been displayed on the screen.

In some instances, it may not even be an issue of synchronous; it could be that the interaction with the server is occurring so rapidly that the server is unprepared and starts to behave strangely (like sending duplicate lines). It's not clear why the server is providing duplicated output, but it will take more resources and time to uncover what might be going wrong.

If you desire that we spend further resources helping you track down the cause of the issue, please send email to support@vandyke.com with a subject of "ATTN: Todd (Form post #11107)". In the body of the email message, please include your SecureCRT serial number (which can be found by choosing Help -> About SecureCRT...).
__________________
--Todd

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

Last edited by rtb; 07-11-2013 at 09:36 AM.
Reply With Quote
  #7  
Old 07-11-2013, 12:54 AM
emailsbecker emailsbecker is offline
Registered User
 
Join Date: Apr 2011
Posts: 74
Hi Todd,

Well, you've given me something I can do on my end first - confirm that I haven't left out any WaitFor elements. I haven't heard back from my inquiry to management about who maintains our bastion server, I'll see what I can find out on that area as well before engaging you further on this issue.

Thanks
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 03:17 AM.