Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #151  
Old 04-19-2019, 12:25 AM
msia0808 msia0808 is offline
Registered User
 
Join Date: Apr 2019
Posts: 1
How to keep all connections tab open

How to modify the script in order that existing session remains open and then it open a new session tab then repeat again until all the hosts are completed? I want to manually validate all configuration before committing the change.

Previously I have tried to comment out line 510-514, the first session did not terminate (as how I want it), then it open a new session tab but won’t enter credentials.
Do
g_objNewTab.Session.Disconnect
crt.Sleep 100
Loop While g_objNewTab.Session.Connected
Reply With Quote
  #152  
Old 04-14-2020, 10:52 AM
Ulua Ulua is offline
Registered User
 
Join Date: May 2019
Posts: 8
RunCommandsOnMultipleHostsAndLogResults.py.

Can these scripts run-in Windows 10 in a SecureCrt 7.1? Thank you...

Because I am getting these errors below:

https://docs.google.com/drawings/d/1...btCXPHu5o/edit


Ulua.

Last edited by Ulua; 04-14-2020 at 11:30 AM. Reason: Added more information.
Reply With Quote
  #153  
Old 04-14-2020, 11:28 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,436
Hi Ulua,

Offhand I do not know of any specific methods or properties used in the script that would prevent it from running successfully in SecureCRT v7.1. However, official support for Windows 10 began with SecureCRT v7.3.x.

If using a newer version is at all possible (version 8.7.1 is available for evaluation), it is recommended.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #154  
Old 04-14-2020, 11:32 AM
Ulua Ulua is offline
Registered User
 
Join Date: May 2019
Posts: 8
Smile

Hi bgagnon,

That makes a lot of sense, that error is because of my SecureCRT version. Thank you for the quick response.

Ulua
Reply With Quote
  #155  
Old 04-14-2020, 11:46 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,436
Hi Ulua,

Sorry, I get an email as a result of your post. You must have added the info about the error after the email was sent.

I cannot open that document.

What error are you getting?
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #156  
Old 06-25-2020, 05:43 AM
gmlabs gmlabs is offline
Registered User
 
Join Date: Jun 2020
Posts: 1
Running script instead of command.txt

I'm trying to run a recorded script instead of text in the command file.
I have had success adding the code just before "g_objNewTab.Screen.Send("{0}\r".format(strCommand))" , but the indent is killing me and quick cut and paste from recorded script would be nice.

Is there an easier way to add a sub that can be called ?
Reply With Quote
  #157  
Old 06-25-2020, 11:15 AM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,031
Quote:
Originally Posted by gmlabs View Post
I'm trying to run a recorded script instead of text in the command file.
I have had success adding the code just before "g_objNewTab.Screen.Send("{0}\r".format(strCommand))" , but the indent is killing me and quick cut and paste from recorded script would be nice.

Is there an easier way to add a sub that can be called ?
There isn't any easy way to do what you want.

This script example is designed to read commands that are literal text strings that get sent (without modification) to the remote system.

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #158  
Old 07-16-2020, 02:53 PM
dav-parker dav-parker is offline
Registered User
 
Join Date: Jul 2020
Posts: 6
Script issues

I'm using SecureCRT 8.7.2 on Windows 10.

I'm wondering if VBScript has changed since this scrtipt was written. First, the string manipulation for the file paths can't work.

g_strHostsFile = g_strMyDocs & "\##hosts.txt" will throw an error when trying to read the file. The preceding "\" has to be removed.

Getting past that, I am trying to do a simple "show int ip brief" on an ASA platform. I have two hosts with the login info saved. When I launch the session from session manager, the session connects and logs in automatically.

I add the two sessions to my ##hosts.txt file and using the default ##commands.txt file with the "show int ip br" command.

When I run the script, I see where it attempts to connect to each session I get something like the following for each session.

Please enter login information for 10.1.20.2.
Username:
username
Please enter login information for 10.1.20.2.
Username: The private key file could not be found:
::rawkey

Note that the public key file and private key file must have the same name (e.g., "Identity.pub" and "Identity") and must be located in the same folder.

The system cannot find the path specified.

Password:
Password authentication failed.
The server has disconnected with an error. Server message reads:
A protocol error occurred. Out of context message type 97
Reply With Quote
  #159  
Old 07-16-2020, 03:55 PM
dav-parker dav-parker is offline
Registered User
 
Join Date: Jul 2020
Posts: 6
Re: Script issues

OK, I think I'm making progress. The host name apparently has to match the name of the sessions ini filename.

The script now seems to get stuck after the prompt changes when entering enable mode. The last char changes from a '>' to a '#'.

The script gets hung at:

strResult = g_objNewTab.Screen.ReadString(strPrompt)
Reply With Quote
  #160  
Old 07-16-2020, 04:20 PM
dav-parker dav-parker is offline
Registered User
 
Join Date: Jul 2020
Posts: 6
Re: Script issues

##commands.txt
enable
show int ip brief
exit

A02-ASA>
A02-ASA> enable
Password: ********
A02-ASA#

I cancel the script on line 428

strResult = g_objNewTab.Screen.ReadString(strPrompt)

I can see that the first "enable" command gets sent.
The session automatically enters the password but the script is stuck at this point. It appears that the "#" is one of the cases in waitforstrings method.

Case 6,7,8 ' "$", "#", or ">"

Any thoughts?
Reply With Quote
  #161  
Old 07-16-2020, 05:40 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,031
Hi dav-parker,

Quoting your most recent...
Quote:
Originally Posted by dav-parker View Post
##commands.txt
Code:
enable
show int ip brief
exit
Output:
Code:
A02-ASA> 
A02-ASA> enable
Password: ********
A02-ASA#
I cancel the script on line 428

strResult = g_objNewTab.Screen.ReadString(strPrompt)

I can see that the first "enable" command gets sent.
The session automatically enters the password but the script is stuck at this point. It appears that the "#" is one of the cases in waitforstrings method.

Case 6,7,8 ' "$", "#", or ">"

Any thoughts?
... I do have some thoughts for you!

As documented on lines 365-368 of the example script code itself...
Code:
' Get the shell prompt so that we can know what to look for when
' determining if the command is completed. Won't work if the
' prompt is dynamic (e.g. changes according to current working
' folder, etc)
...your 'enable' command is issued at a command prompt level that ends in a '>' character, after which the prompt changes to one that ends with a '#' character. This script example isn't designed to accommodate commands that change the shell prompt.

Commands from the ##commands.txt file don't get issued until ***AFTER*** the Connect() function call is made, so your reference to Case 6,7,8 isn't immediately relevant -- "That ship has already sailed".

There's no "easy button" fix for your plight, but one idea would be to modify your Connect() function so that if you detect the ">" user level prompt there, you could then issue the necessary enable command and send the corresponding password needed. This way, your shell prompt will end with a # when the Connect() function returns, allowing your ##commands.txt file to focus on everything but the 'enable' command and its requisite password handling.

For example, inside of your Connect() function, theoretically replacing your 'Case 6,7,8...' block, you'd have this instead:
Code:
Case 6,7,8 ' "$", "#", or ">" <-- Shell prompt means auth success
    g_objNewTab.Session.SetStatusText _
        "Connected to " & g_strHost & " as " & g_strUsername
    
    ' Check to see if the prompt level is a ">". If it is, then
    ' run the 'enable' command and provide the necessary enable
    ' pass, prompting for it as needed.
    If g_objNewTab.Screen.MatchIndex = 8 Then
        ' Special case for the ">" prompt... Cisco user priv prompt, anyone?
        ' Do we have an enable password yet? If not, prompt the
        ' end user for it.
        If g_strEnablePass = "<not-yet-specified>" Then
            g_strEnablePass = crt.Dialog.Prompt( _
                "Please specify the 'enable' password." & vbcrlf & _
                vbcrlf & _
                "If no enable command is desired, enter ""<none>""", _
                "Enable Password?", _
                "<none>", _
                True)
            If g_strEnablePass = "" Then
                ' User canceled the Enable Password prompt. Let's bail:
                g_objNewTab.Screen.SendSpecial("MENU_SCRIPT_CANCEL")
            End If
        End If
        
        If g_strEnablePass <> "<none>" Then
            ' Send the 'enable' command:
            g_objNewTab.Screen.Send "enable" & vbcr
            
            ' Wait for the enable password prompt:
            g_objNewTab.Screen.WaitForStrings("ssword:")
            
            ' Send the enable password:
            g_objNewTab.Screen.Send g_strEnablePass & vbcr
            
            ' If the correct password was entered, then the
            ' rest of this code handles itself because the 
            ' next iteration of this loop in Connect() will
            ' Find the # privileged shell prompt.
            
            ' If you want to enable bad password handling,
            ' this is where you'd do it.
        End If
    Else
        ' MatchIndex wasn't 8, so the shell prompt wasn't ">".
        ' This means that we either don't care or don't need
        ' to issue any 'enable' command.
        Exit Do
    End If
Based on the replacement block I've postulated with the untested code snippet idea I've cobbled together above, there would need to be a new line/statement inserted near the top of your script code file (after all the leading comments, but before MainSub() gets called on line 182) that defines the global g_strEnablePass for use in authenticating to those hosts that need it:
Code:
g_strEnablePass = "<not-yet-specified>"
Best wishes to you and your scripting project.
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #162  
Old 07-16-2020, 05:53 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,031
Hi dav-parker,

To clarify...
Quote:
Originally Posted by dav-parker View Post
The host name apparently has to match the name of the sessions ini filename.
...the host name only needs to match the name of an existing saved session if you want to use existing saved sessions -- that's the default behavior of the script.

If desired, you can use ad hoc connections (specify IP addresses or direct host names instead of saved session names in the ##hosts.txt file)... you just have to turn off the bUseExistingSessions variable in the script that says saved sessions are being used:

Default value (use saved sessions)...
Code:
Dim g_bUseExistingSessions
g_bUseExistingSessions = True
... vs. customized (make ad hoc connections)…
Code:
Dim g_bUseExistingSessions
g_bUseExistingSessions = False
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #163  
Old 07-17-2020, 08:20 AM
dav-parker dav-parker is offline
Registered User
 
Join Date: Jul 2020
Posts: 6
Quote:
Based on the replacement block I've postulated with the untested code snippet idea I've cobbled together above, there would need to be a new line/statement inserted near the top of your script code file (after all the leading comments, but before MainSub() gets called on line 182) that defines the global g_strEnablePass for use in authenticating to those hosts that need it:
Code:
g_strEnablePass = "<not-yet-specified>"
Best wishes to you and your scripting project
Cool, thanks. It is working now.
I tweaked it slightly since since the session automatically enters the enable password:

Code:
Else
   ' if enable password is stored in session, just send enable
    g_objNewTab.Screen.Send "enable" & vbcr
End If
Update
FYI, going into conf t mode caused the script to get stuck again.
I noticed in a previous post that to get around this, just hard code the strPrompt = "#".
Looks good to go.
Seems like changing the way dynamic prompting is handled might help a lot of people with scripting. Maybe grab the initial prompt but compare original string to new prompt (length original - 1) + rightmost character to cover the trailing # character.

Last edited by dav-parker; 07-17-2020 at 11:17 AM. Reason: Fix missing [QUOTE] tag and wrap additional code in [CODE][/CODE] tags
Reply With Quote
  #164  
Old 07-17-2020, 12:40 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,031
Quote:
Originally Posted by dav-parker View Post
Seems like changing the way dynamic prompting is handled might help a lot of people with scripting. Maybe grab the initial prompt but compare original string to new prompt (length original - 1) + rightmost character to cover the trailing # character.
Good thought, except for these issues:
  1. How do you know what the "new prompt" is? You have to know what it is (before hand) in order to wait for it.
  2. Eventually even if you know what the prompt text is right now, you might actually issue a command that causes the prompt to change to be shorter (like exiting config mode or dhcp pool mode, etc).... in which case you would have to know *all* of the possible ways that a command might end up changing the prompt *AND* know exactly what the new prompt text is going to be.
Short of supporting regular expressions in WaitFor*() and ReadString() calls, using # is currently the best bet if you're on a Cisco machine and your commands will end up changing the CLI shell prompt.

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #165  
Old 07-31-2020, 02:39 PM
dav-parker dav-parker is offline
Registered User
 
Join Date: Jul 2020
Posts: 6
WaitForString strCommand

For the most part, I can do most of what I need. But, I've run across a new issue. I'm sending several commands to modify ACLs on an ASA. The script gets stuck at:

g_objNewTab.Screen.WaitForString strCommand

It appears that the ACL command is long enough that it doesn't display the entire command back. It wraps. So basically, the script hangs and cannot proceed.

Any good thoughts as to how to work around this?

Thanks,
David
Reply With Quote
Reply

Tags
example script


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:17 PM.