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 10-29-2013, 06:20 PM
vramaswa vramaswa is offline
Registered User
 
Join Date: Oct 2013
Posts: 13
default sesssion from import

Thank you the script to import hosts to sCRT.
I have one issue though. The sessions created via the script do not have the 'default session' settings that I already have (When I use Quick connect and enter a host, sCRT uses the default session creds to login). Is there a way to use it or may be I missing something? Appreciate your help. sCRT is amazing!
Reply With Quote
  #2  
Old 10-30-2013, 09:26 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,544
Hello vramaswa,

I have moved this post to its own thread.

For the most recent version of any script you find in the forums, you may want to check this sticky that was created to hold script examples.

You are correct that the Import Arbitrary script example does not use Default Session. In fact, the sessions are created the old way, by writing out to the ini file itself (as opposed to using SessionConfiguration object).

One of the fields that can be imported via that script is username. For password, you can just use the Default Session (or multiple session) tip to apply (or reapply) that information to all sessions again. If you have previously applied username/password via Default Session, it may be a multi-step process.

Note that this would, of course, only be applicable if *all sessions* use the same password.

Since the information has *already* been saved in the Default Session file itself, you would have to go through the process and clear the information from the password field (or enter something like tempPW) and then go through the process again and apply the correct password.

It is always recommended you backup your config before applying changes that affect multiple sessions. The location of your installation's Configuration folder is found in the General category of SecureCRT's Global Options.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 10-30-2013, 02:32 PM
vramaswa vramaswa is offline
Registered User
 
Join Date: Oct 2013
Posts: 13
Thanks Brenda. Would you have an updated script that uses the object instead. Or is there another way of importing hosts from a database or a file? I have a Putty Connection Manager database(.dat file), would you have an import script that works with that (+ take care of the default session settings?)

Thanks
Reply With Quote
  #4  
Old 10-30-2013, 03:20 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,544
Hello vramaswa,

We do have a different script example for importing connections from Putty Connection Manager. See this forum post.
__________________
Thanks,
--Brenda

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

Last edited by jdev; 04-22-2020 at 04:28 PM.
Reply With Quote
  #5  
Old 10-31-2013, 03:22 AM
ogun ogun is offline
Registered User
 
Join Date: Sep 2013
Posts: 15
I wrote the following script for our needs.
It reads a csv file with three columns:
hostname, folder, description

It then creates sessions for each in a session folder named shared, each session a copy of the default session.

We use it as a way of having a shared session database, using urlget to grab the CSV file.

Since I can't find the attach file option, I'll just code tag it instead
Code:
#$language = "Python"
#$interface = "1.0"

# Top level folder to put all sessions in.
TOPLEVEL = "Shared"
INPUTFILE = "devices.csv"

import SecureCRT
import csv
import os.path
import shutil


def main():
    # Open file for reading
    # We expect the CSV file to have three columns per line:
    # Hostname, Folder, Description
    csvfile = open(INPUTFILE)
    csvreader = csv.reader(csvfile)

    # Remove existing folder, we rebuild every time.
    script_name = crt.ScriptFullName
    script_dir = os.path.dirname(script_name)

    # We expect to be in $CONFIG/Scripts with the sessions in $CONFIG/Sessions
    sessions_folder = os.path.join(script_dir, '../Sessions')

    # Did we get it right?
    if not os.path.isdir(sessions_folder):
        msg = "Could not find sessions folder. Got %s" % sessions_folder
        crt.Dialog.MessageBox(msg)
        return

    # Append top level
    shared_folder = os.path.join(sessions_folder, TOPLEVEL)

    # Delete old folder
    if os.path.exists(shared_folder):
        shutil.rmtree(shared_folder)

    # Open the default session to use as a template for created sessions
    session = crt.OpenSessionConfiguration('Default')

    for line in csvreader:
        sessionname = line[0].split('.')[0]
        hostname = line[0]
        folder = TOPLEVEL + "\\" + line[1]
        comment = line[2]

        session.SetOption('Protocol Name', 'SSH2')
        session.SetOption('[SSH2] Port', 22)
        session.SetOption('Hostname', hostname)
        session.SetOption('Description', [comment])

        session.Save(folder + "\\" + sessionname)

# Do the running
main()
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:51 AM.