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 12-01-2008, 11:08 AM
seteshpl seteshpl is offline
Registered User
 
Join Date: Nov 2008
Posts: 10
Automatic configuration

Hello,

I want to be able to put all my config settings for cisco router by using script.
So far I have the following script:

Code:
# $language = "VBScript"
# $interface = "1.0"

Sub Main
Const DEVICE_FILE_PATH = "c:\config.txt" 
Set fso = CreateObject("Scripting.FileSystemObject")
Set myFile = fso.OpenTextFile(DEVICE_FILE_PATH)
While Not myFile.AtEndOfStream
	line = myFile.ReadLine
	crt.Screen.Send( line & vbCR )
	crt.Screen.Send( vbCR )
	crt.Screen.WaitForString( "#" )	
Wend 
End Sub
and it works correctly for small files. When the config file is bigger it behaves exactly when I would copy and paste all data directly to the secureCRT (i.e. I get something like buffer overflow and only first part of the config is entered correctly). How can I handle with this problem? Thanks!
Reply With Quote
  #2  
Old 12-01-2008, 01:42 PM
kbarnette kbarnette is offline
VanDyke Technical Support
 
Join Date: Aug 2007
Posts: 587
Hi seteshpl,

What version of SecureCRT is being used?
Version information can be found in the 'Help/About SecureCRT...' dialog.

What is the exact error that is displayed?

Lastly, does adding the following line within your While loop produce better behavior?

Code:
crt.Sleep 50
Reply With Quote
  #3  
Old 12-02-2008, 12:55 PM
seteshpl seteshpl is offline
Registered User
 
Join Date: Nov 2008
Posts: 10
thanks, I use secureCRT 5.5 and delay helped and now everything is okay except one thing...
on cisco routers when I execute each command, the router executes it and comes back to exec (#) prompt. In my script I wait till next exec prompt to enter new command. But: there is one command: banner motd ^ that allows me to enter motto line by line till I enter ending char ^. How can I make it work in my script (I believe that I should check each line and search for ^ and if I find it then just enter line by line till next ^ is found, but... how can I do this in my simple script?) Thanks!
Reply With Quote
  #4  
Old 12-02-2008, 02:43 PM
kbarnette kbarnette is offline
VanDyke Technical Support
 
Join Date: Aug 2007
Posts: 587
Hi seteshpl,

Thanks for the update. I am glad adding the crt.Sleep line helped to resolve issue.

Regarding your question on different prompts, if I understand correctly your script is already entering the commands line-by-line.

Is this correct?

If so, it seems as though the only issue would be configuring the script to wait for either a '#' symbol, or a '^' character. This can be done with the crt.Screen.WaitForStrings() method, as exemplified below:

Code:
crt.Screen.WaitForStrings "#", "^"
Using this information, are you able to successfully configure your script to handle both the '#' and '^' prompts?
Reply With Quote
  #5  
Old 12-03-2008, 06:28 AM
seteshpl seteshpl is offline
Registered User
 
Join Date: Nov 2008
Posts: 10
Thank you! I didn't know this functionality.
The effect I would like to get is following: if there is no character ^ in the entered line, then enter only this one command (line) wait for sign '#'. If there is a character ^, then enter as many commands (lines) till you see again character ^. Is it possible to do in SecureCRT?

For example:
Code:
# command1 (send and wait for #)
# command2 (send and wait for #)
# command3 ^data (keep sending next lines...)
data1 (send without waiting)
data2 (send without waiting)
data3 (send without waiting)
data4^ (finish sending lines because ^ is observed, go back to standard procedure and wait for #).
# command4 (send and wait for #)
Hope it clarifies my script! Thanks!
Reply With Quote
  #6  
Old 12-03-2008, 04:01 PM
kbarnette kbarnette is offline
VanDyke Technical Support
 
Join Date: Aug 2007
Posts: 587
Hi seteshpl,

This could be done with basic VBScript capabilities not specific to SecureCRT. A boolean variable could be used and set appropriately to determine if SecureCRT should execute the crt.Screen.WaitForString() call.

For example:

Code:
Sub Main
    Const DEVICE_FILE_PATH = "c:\config.txt" 
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set myFile = fso.OpenTextFile(DEVICE_FILE_PATH)

    Dim bWait
    bWait = True

    While Not myFile.AtEndOfStream
        line = myFile.ReadLine
    
        if Instr(line, "^") <> 0 then
            if bWait = True then
                bWait = False
            else
                bWait = True
            end if
        end if
    
        crt.Screen.Send( line & vbCR )
        crt.Screen.Send( vbCR )
        if bWait then
            crt.Screen.WaitForString( "#" ) 
        end if
    
        crt.Sleep 50
    Wend 
End Sub

Is this information helpful?
Reply With Quote
  #7  
Old 12-05-2008, 01:20 AM
seteshpl seteshpl is offline
Registered User
 
Join Date: Nov 2008
Posts: 10
Works perfect - Thanks!!!
Reply With Quote
  #8  
Old 02-04-2009, 03:42 AM
CGG6Rt CGG6Rt is offline
Registered User
 
Join Date: Jan 2009
Posts: 7
Hello,

Is the second line of the following needed ?

crt.Screen.Send( line & vbCR )
crt.Screen.Send( vbCR )

Because there is already a "vbCR" in the first line.
Or is this a "buffer-reason" ?

nice greetings

CGG6Rt
Reply With Quote
  #9  
Old 02-04-2009, 11:29 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,212
Hello CGG6Rt,

That portion of the code was originally provided by seteshpl and could have been specific to his needs regarding the CISCO devices he was working with. It is not clear whether or not it was a timing requirement for his particular environment.

Any comments, seteshpl?
__________________
Thanks,
--Brenda

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

Last edited by jdev; 02-04-2009 at 11:41 AM.
Reply With Quote
  #10  
Old 02-09-2009, 03:55 AM
CGG6Rt CGG6Rt is offline
Registered User
 
Join Date: Jan 2009
Posts: 7
Ok thanks,

I saw that "kbarnette" uses these 2 lines and my thought was
"....a "VanDyke Technical Support User" uses that code, maybe it is must-have to use "vbCR" twice times in that case..."
But know i see my assumption was wrong, because i didn't realize that "kbarnette" only used the code from "seteshpl"

So for me is my question answered, because if have tried it without the second use of "vbCR" in that code in a environment with a cisco device and it works too
But maybe for somebody is the second use of "vbCR" helpful

nice greetings

CGG6Rt
Reply With Quote
  #11  
Old 02-23-2009, 06:58 AM
seteshpl seteshpl is offline
Registered User
 
Join Date: Nov 2008
Posts: 10
Sorry for late response...
Yes, second vbCR is there bacause of my personal reasons... typically on Cisco devices (I am using this script to manage them) are handled correctly without this line. Hope that clarifies... .
Thanks again for the solution!
Reply With Quote
  #12  
Old 02-23-2009, 08:49 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,212
seteshpl,

Thank you for posting the explanation here.
__________________
Thanks,
--Brenda

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 02:11 PM.