Welcome to the VanDyke Software Forums

Join the discussion today!

Go Back   VanDyke Software Forums > Scripting

Thread Tools Rate Thread Display Modes
Old 04-13-2017, 02:11 PM
mybox65 mybox65 is offline
Registered User
Join Date: Feb 2012
Posts: 17
Sending an extra "n" from my script

I just want to capture all configuration by SecureCRT. What I found, every single time when I running my script, it will stopped by sending an extra "n" after several round looping, it causes the output got interrupted, and the Cisco device also does't recognize the command "n" and stop to export reset of configuration. I do not know why my script is always sending a "n" after several round looping (the purpose of looping is trying to send an extra space for removing the --More--breaker from screen )

OUTPUT from the Cisco Device:
interface GigabitEthernet0/0/0/14
circuit-type level-2-only
address-family ipv4 unicast
interface GigabitEthernet0/1/0/15
address-family ipv4 unicast
interface GigabitEthernet0/1/0/19
circuit-type level-2-only
address-family ipv4 unicast
interface TenGigE0/2/0/3
circuit-type level-2-only
address-family ipv4 unicast
--More-- ---->it is a "output data breaker", If a "--More--" prompt was found, my script code simply accumulates the data read from the remote and presses the space bar so that more data will be sent from the cisco device.

Problem from output of the Cisco device :

interface Loopback0
ipv4 address
interface Loopback2
description Lab
vrf Lab
ipv4 address
RP/0/RSP0/CPU0:TULA-RT2#n ------>I do not know where the "n" from is
% Ambiguous command: "n"

My Script:
# $language = "VBScript"
# $interface = "1.0"
Dim nresult,g_var1,str1,strResult,strCompleteOutput,dname,screenrow

Sub Main
  crt.Screen.Synchronous = True
  crt.Screen.IgnoreEscape = True
Dim fHosts(5)
fHosts(0) = ""
fHosts(1) = ""
fHosts(2) = ""

For Each stHost In fHosts
   If stHost = "" Then Exit For
   crt.Session.Connect  "/TELNET "&stHost
   On Error Resume Next
   On Error Goto 0
   crt.sleep 2000  
nresult =""
strResult = ""

    nresult = crt.screen.WaitForStrings ("#", "sername:",">","Login invalid")
    Select Case nResult
        Case 1
	    crt.Screen.Send vbcr
            exit do
        Case 2
            crt.Screen.Send "username1" & vbcr
	    crt.Screen.Send "password1" & vbcr

        Case 3
            crt.Screen.Send "en" & vbcr
	    crt.Screen.Send "username2"  & vbcr
	    crt.Screen.Send "password2" & vbcr
        Case 4 
	       crt.Screen.Send vbcr
        End Select
		If crt.Screen.waitForString ("#") = True Then
		screenrow = crt.screen.CurrentRow
		dname = crt.Screen.Get(screenrow, 1, screenrow, 9 )
		logfile = "D:\Logs\%H--" & dname & "%M-%D--%h'%m.txt"
		crt.Session.LogFileName = logfile
        		crt.Screen.Send " show running-config  " & vbcr
 			strResult = crt.Screen.ReadString ("-- More --"," --More-- ","!" & vbcrlf & "end","end" & vbcrlf)
 			If crt.Screen.MatchIndex < 3 Then 
				crt.Sleep 900
				crt.Screen.Send " "
				End if
 			If crt.Screen.MatchIndex >= 3 Then Exit Do
                crt.Session.Log False
	      MsgBox "Not found, moving on!!"
        End if
   MsgBox "Boss, the job is done!!!"	
crt.Screen.Synchronous = False
End Sub

Last edited by mybox65; 04-13-2017 at 02:46 PM.
Reply With Quote
Old 04-13-2017, 04:07 PM
bgagnon bgagnon is offline
VanDyke Technical Support
Join Date: Oct 2008
Posts: 4,295
Hi Boss!

I am not for certain where the "n" is coming from at this point but I do see a violation of a "best practice" that may be a contributing factor.

In section 4.2 of the scripting manual, the author advises that you always use an intervening WaitForString() with every Send(). Otherwise, your script can get out of sync and it sounds like that may be happening here.

So I would definitely recommend adding WaitForStrings() after every Send(). Also, you may need to make the WaitForString/ReadString of # more specific.

Could a # (or >) be appearing in the output when you run the "show config" command?

More to discuss, but let's see what your results are after following best practice.

VanDyke Software
Technical Support
(505) 332-5730
Reply With Quote
Old 04-13-2017, 10:51 PM
Casey Casey is offline
Registered User
Join Date: Oct 2011
Posts: 114
Is there a reason you aren't just issuing a "terminal length 0" command before you show the running config?

'terminal length 0' will disable the screen pausing all together for the session. Do away with all the looping and just re-enable it later if you want.
Reply With Quote

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 07:31 PM.