SUPPORT > TIPS
Send us a question or comment

   

Importing SecureCRT® Sessions from a Data File

Note: This tip is for use with SecureCRT for Windows® and provides example scripts that use VBScript.

Recreating your SecureCRT sessions can be easy if you keep a list of the servers, routers, and other devices that you need to connect to saved in a .csv or other type of data file. With a data file, you can use a script to import the data into SecureCRT sessions, rather than manually creating them one at a time. In this tip, we explain how to set up an example data file, and we provide an example VBScript for you to use and modify for your specific setup. You only need a few basic script-writing skills to get started (more extensive knowledge may be required to customize the example script to meet your needs).

The example script gathers information about your host machines from your .csv data file in order to create the .ini files that will become your SecureCRT sessions. There are comments within the script code explaining the expected format and organization of the data file. The comment lines in the script begin with a single quote character (') and, as comments, they do not affect the functionality of the script.

The following steps show you how you might use the techniques described in the script to generate sessions from your data file.

Setting up the data file

The first thing you'll need is a data file that contains the host information. The format below most closely matches the format that the script uses. If your data file only includes some of the information, you can edit the script so that it only looks for the items that you actually have in the data file. The following is an example of what your data file might look like:

    hostname,protocol,username,folder,emulation
    192.168.0.1,SSH2,root,Linux Machines,XTerm
    192.168.0.2,SSH2,root,Linux Machines,XTerm

    10.0.100.1,SSH1,admin,CISCO Routers,VT100
    10.0.101.1,SSH1,admin,CISCO Routers,VT100

    myhost.domain.com,SSH2,administrator,Windows Servers,VShell
    myhost2.domain.com,SSH2,administrator,Windows Servers,VShell

    555-1212,tapi,n/a,TAPI Sessions,VT100
    555-1213,tapi,n/a,TAPI Sessions,VT100

The first line names the fields used and their order. This example uses a comma as the delimiter between fields, but the script can work using a comma, space, semicolon, or tab as the delimiter. If your delimiter character is not a comma, you can "comment out" line 58 of the script by inserting a single quote at the beginning of the line, and then remove the comment character from the beginning of one of the subsequent lines that matches your delimiter character.  Or, simply modify the value of the g_strDelimiter variable on line 58 to match your specific delimiter character(s).

Note: The value of the emulation field must match a valid SecureCRT emulation option as displayed in the Terminal option in the Terminal / Emulation category of the Session Options dialog.  The only protocol not currently handled by the example script code is the Serial protocol.  If you need to import a large number of Serial session configurations, take a look at how the script code handles TAPI data, as it may give you some ideas about script modifications you might be able to put in place to meet your importing needs.

The field keywords that the script can already use are as follows:

session_name The value that will be used for the session’s name. If this field does not exist, the hostname field is used as the session_name.
folder A relative folder path for the specified session (not including the session name) as displayed in the Connect dialog. Any folder that does not exist will be automatically created as the script runs.
hostname Required. The hostname or IP address for the remote server (for TAPI protocol sessions, specify the complete phone number here in the hostname field).
protocol Required.  The protocol to be used for connecting with the session (SSH2, SSH1, Telnet, RLogin, or TAPI).
port The port on which the remote server is listening.
username Username for the account on the remote server.
emulation The emulation (vt100, xterm, etc.)
description Comment/description. Multiple lines are separated with \r

The example data file above doesn't include a session_name field, so the hostname information will be used as both the hostname and the session name.

If you look at line 87 of the example script, you will see that, by default, the script is expecting the data file to be named MyDataFile.csv and to be located in C:\Temp\MyDataFile.csv. You can either move and rename your data file to match the name and location in the example script, or you can edit that line of code in the script to point to your data file.

If you look at lines 141-143 of the script, you will see that the script reads the current user's registry to find the location of your Config folder where it will create your new sessions by default. The location it finds in the registry should usually correspond to the Configuration Folder path you see in the General category of the Global Options dialog.  When this script is launched, it will prompt you for the folder in which you would like to store imported .ini files, defaulting to the current location of your configuration folder as indicated in the global options.  If you launch SecureCRT with a shortcut that uses the /F command-line argument to specify a different location for the configuration folder, you’ll need to enter this special configuration folder location manually rather than trust in the default value that is read in from the registry.

Running the script

Once you have made the necessary configuration changes to your data file and/or the script, you can launch the script by double-clicking on the script filename in Windows Explorer. You will be prompted to specify the location of the host data file to be imported:

Once you have specified your data file, you should see the following pop-up message, which allows you to confirm or change the location of your Config folder.  We suggest that when testing (to ensure that the script does what you desire), you specify a temporary folder as the destination folder so that imported session .ini files can be inspected and reviewed after the script has run its course – without affecting your current configuration.

Once the destination path has been specified and the OK button has been pressed, the script will attempt to create sessions using the data provided in the file.  After the work has been completed, the script will write information to a log file stored within the specified configuration folder and then launch the file with your computer's default .txt file handler.

Notice that since lines 4, 7, and 10 of our example data file presented earlier were blank, the report indicates that sessions were not created for the data contained on those lines.

After the script has completed, you can open the SecureCRT application and view the Connect dialog to see the sessions that have been created.

Here is the sample VBScript code for the import script in its entirety. (Note: for this script to work properly, you should save the file with a .vbs extension):

ImportArbitraryDataFromFileToCRTSessions.txt

Was this information helpful?
Yes No
Thank you!
Send your comments and questions to VanDyke Software Support,
or join the discussion in the VanDyke Software Forums.
Can't find the answer you're looking for?
Ask VanDyke Software Support directly
and we will get back to you as soon as possible.
1.  Read or download one of our secure solutions white papers. 2.  Download a free
30-day evaluation copy of our products.
3.  Let us help define the right Secure Shell solution for your company. 4.  Subscribe to our What's New page for tips, solution ideas, and product news.