Welcome to the VanDyke Software Forums

Join the discussion today!

Go Back   VanDyke Software Forums > Scripting


Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
Old 03-22-2012, 06:10 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,099
Post Script Examples

This specialized thread posting contains example scripts that can be used with VanDyke Software products, focusing primarily on SecureCRT.

Script examples are attached as .txt files. After saving an example script file to your system, you may need to change the extension from .txt to either .vbs or .py depending on whether it's a VBScript or Python example.

The examples here merely provide you with a starting point for creating your own scripting solutions.
Although a script example may appear to do "exactly what you need", the scripts listed here will almost always need to be modified to meet your own specific needs.

This "sticky" thread is closed to feedback to prevent it from becoming difficult to read/search. VanDyke Software technical support staff may post new and update existing examples as time and resources allow. You are encouraged to provide feedback related to these examples by email, web, or a separate thread in the scripting forum.

VBScript and Python Examples for SecureCRT
Cisco Save Running/Startup Config to Local File
Written in Python so as to be able to run on Windows/Linux/MacOSX versions of SecureCRT. If you're already connected to the device using SecureCRT, the script saves your Cisco router running-config or startup-config to a local file with the press of a button.
Close All But Current Tab
Illustrates how to close all open tabs. It is possible to modify the behavior of the script by passing arguments to the script. The script can be run manually from the Script menu or by mapping a button or key combination.
Color Scheme Scripting
Need to quickly adjust your colors based on existing color schemes defined in SecureCRT? Two example scripts show how you can save clicks while you enjoy rapid color scheme selection.
Watch the video: Color Schemes and ANSI Color Palettes
Command Window Automation
Demonstrates how to automate the Command Window (formerly known as the "chat window") in SecureCRT 7.2 and newer.
Connect in Tab to Host and Handle Authentication in Terminal Window
Prompts for host/IP, username, and password (if not hard-coded in the script variables strHost, strUser, and strPwd), and then uses the information to connect to the host using the SSH2 protocol. The session configuration object is used to detect if the option is enabled for handling authentication in the terminal window, and prompts the user to have this script automatically enable it if the option is not currently enabled. SSH2 authentication is handled by waiting for the username and password prompts and sending the username and password, respectively.
Connect to Hosts in the Clipboard (one per line)
Shows how to instruct SecureCRT to establish ad hoc connections to hosts listed one by one in the clipboard.
Convert Clipboard, LF, CR, Space, and Tab
Shows one way to convert certain characters within the windows clipboard prior to pasting to the remote or after being copied from the SecureCRT terminal window. A separate UI is displayed, offering options for conversion.
Get Configuration Path
Shows how to acquire the folder/directory from which SecureCRT is loading/saving configuration settings. Cross-platform Python example will work in SecureCRT on both Windows and Mac/Linux platforms. VBScript example will work only in SecureCRT on Windows.
Get Tab By Name
Shows how to get a reference to a tab object by supplying the tab name. Examples provided for both VBScript and python.
Import Arbitrary Data From File to SecureCRT Sessions
Shows how to create sessions from information in a text file (.csv format by default, but you can edit to fit the format you have).
Import Keyword Highlighting INI File in SecureCRT
This example demonstrates an easy way to import a Keyword Highlighting INI file into SecureCRT.
Watch the video: Keyword Highlighting in SecureCRT -- Watch the video: Importing a Keyword INI File into SecureCRT
Import Putty Connections to SecureCRT Saved Sessions
Pretty self-explanatory: Imports putty configurations into SecureCRT saved sessions. Different example scripts are available to import from putty, mputty, putty-cm, and super putty.
Integrating with Microsoft Excel
Several examples demonstrating use of Excel to read, write or search for data.
Iterate Over Saved Sessions
Demonstrates how to iterate over all saved sessions to perform an action. Examples show how to export session data to a file (CSV or INI/.conf format)
Jump Host - Handle Secondary Host Connection Attempts
Connected to a jump host and want an example of automating 'ssh' or 'telnet' connection attempts from that remote shell to another system? This example shows you a best practice way to accomplish this task.
Launch RDP or HTTP Connections from SecureCRT Sessions
An approach to managing RDP/HTTP/HTTPS connections from within SecureCRT's session manager.
Logging Status and Statistics in SecureCRT's Status Bar
An example of how to use a script to show SecureCRT's logging status (On|Off) and statistics (# of lines, size) in the status bar for the current tab/session.
Open SecureCRT's Log File/Folder
Shows how a script can be launched from a button to open SecureCRT's log file/folder.
Pass Through Printing to File
In cases where the remote legacy app running on your connected host provides for retrieving desired ASCII data only via pass through printing codes, this script example demonstrates one way of saving this data to a file instead of having to print to a physical printer.
Paste (or Send ASCII File) with Echo Flow Control
Demonstrates how to send data from the clipboard (or read in from a file) to a remote system, sending each line one at a time and waiting for prior lines to be echoed back by the remote system before moving on with sending subsequent lines.
Ping Host from Clipboard/Selection Using Local Shell Connection
Shows how to utilize the Local Shell capability of SecureCRT to launch a 'ping' command for a specified host (target host can be specified via the clipboard, selection in the terminal screen, or a prompt window).
Python - Importing custom modules which reference the crt object
Examples showing techniques for importing your custom-written python modules which need to reference the crt scripting object.
Python - Lookup Data from CSV File Using CSV Reader
Python example shows how to use the native python csv reader to read data from a CSV file and perform a lookup of related data coming from the same row in the file.
Reveal Non-Printing Characters
Demonstrates how to "reveal" non-printing characters that are present in the clipboard (CR, LF, etc. as examples of non-printing characters).
Run Commands on Multiple Hosts and Log Results
(AKA: Read Data From Separate Hosts/Commands File And Log To Individual Files)
Demonstrates how to connect to hosts read in from a "hosts" file and for each host, send a list of commands read in from a "commands" file. Results are logged to separate, uniquely-named files based on the host address and optionally the commands that are executed.
Save Screen Text to a File
Demonstrates how to easily/quickly save text from the screen/scrollback to a file. Three separate modes are available for deciding what text to save: selected text, all screen text, or all text on both screen & scrollback buffer.
Save Selected Text to CSV File
Allows you to quickly save columns of space-separated data selected in SecureCRT's terminal screen to a CSV file. Automatically launches the CSV file for viewing/editing in the system's default CSV app.
Send Command With Date/Time Substitutions
An example which allows SecureCRT to automatically convert date/time substitution parameters (e.g. %Y, %M, %D, etc.) when sending a command.
Send Lines One by One with Skips and Substitutions
An example which brings up a separate UI allowing you to control the sending of lines, one by one, as read in from a file. You can define substitution variables, allowing you to leverage the same sequence of lines, but with different values in specific places. If the current line is one you want to skip, just press the Skip button to move on to the next one.
Set Trace Level
Shows how to set a more/less verbosity level for SecureCRT's "Trace Options" functionality. Often when troubleshooting a connectivity issue between client and server, it's helpful to know more about what's going on lower down in the protocol. If VanDyke Software technical support asks you to set Trace Level to a value greater than one, consider this script as an alternative to manually editing the .ini file.
SFTP Tab Automation
Demonstrates opening an SFTP tab & programmatically driving a file download. Prior to running this script, the currently active tab must already be connected with the SSH2 protocol to a remote server that is capable of providing SFTP functionality; otherwise an error will occur and script execution will be halted.
Watch the video: The SFTP Tab in SecureCRT
Store Command Results in the Clipboard
Example script which made an appearance in the Advanced Copy & Paste in SecureCRT video on our You Tube channel. It can be used to automatically copy results of remote commands into the clipboard (so you don't even have to spend valuable time selecting the results with your mouse).
TAPI Replacement Dialer - Use Serial
This Windows-only example script shows one alternative to using TAPI. It uses the Serial protocol to connect to the COM port of your modem, and does the dialing instead of farming the job off to the Windows TAPI system.
Use 'Description' Field of Saved Sessions as Script Argument
Shows how you can use the "Description" field of a saved session to store data that you need to use somewhere within your script, but you don't want to hard-code it (because it might be session-specific, for instance).
Word Delimiter Rotation
Shows one way of cycling through different delimiter sets for double-click word selection. Having mapped a button on SecureCRT's button bar to run this script, SecureCRT's word delimiters for the active session particular session will change with each button press, rotating through 5 different word delimiter set examples.
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support

Last edited by jdev; 02-25-2021 at 04:41 PM. Reason: Added "Send Command with Date/Time Substitutions" example

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 06:01 AM.