Scripting Examples

Example Python Scripts for SecureCRT® for Windows and Mac

The following scripts written in Python are examples of how to perform specific tasks using the Python script execution capabilities of SecureCRT for Windows and Mac. They can also be used as a guide to writing your own scripts.

Connecting From Within a Script

Connect with SecureCRT using the SSH2 protocol.
Connect using the telnet protocol and automate login.

Sending Commands and Data To a Server Set up a list of commands or text to send to the remote when a corresponding trigger is detected. Connects to multiple sessions and sends a series of commands. Captures the output of the 'ls' command and displays it in a message box. Sends the same command to all tabs that currently have an active connection.
Opens a file and sends its contents line by line.
Opens a file and does some processing of the text before sending it.
Uploads a text file to a server by sending it line by line and directing output to a file. Automates setting the DISPLAY shell variable to enable remote display of X clients. Automates setting the LINES and COLUMNS shell variables for terminal environments where these variables are not set properly. Simulates pressing a function key.

Retrieving Output From a Server The results of specific commands are captured and stored in the clipboard. Demonstrates use of the Get() function to read data from the screen. Uses the Get() function to read data from the screen and write data to a spreadsheet file. Uses the Get() function to read data from the screen and write it to a text file. The results of specific commands are written to log files.

Miscellaneous Scripts Prompts for a comment to add to the log file. Saves the selected text to a file.