Welcome to the VanDyke Software Forums

Join the discussion today!

Go Back   VanDyke Software Forums > Scripting


Thread Tools Rate Thread Display Modes
Old 03-26-2009, 02:52 PM
slouw slouw is offline
Registered User
Join Date: Nov 2005
Posts: 166
GetOption, syntax

My logfilename has the following format:
%Y-%M-%D %hh%mm%ss Hostname.log
I am trying to stop logging, start a new log file with my existing Log file name but appending a string TempStr to the new logfilename. Effectively thus:
%Y-%M-%D %hh%mm%ss Hostname TempStr.log

Q1 It seemd the way to go here is to use the GetOption Method of the SessionConfiguration object. I see one relevant post here:
Q1 = Is this indeed the way to go or not?

Q2: In regards to the GetOption Method of the SessionConfiguration object I could replicate retrieving the "Hostname" field from the Session Options as described in the post above. I could not retrive any other parameter though, for instance the Port parameter, or the Name parameter. So these would work:
Crt.Dialog.MessageBox("Hostname1 is: " & Crt.GetScriptTab.Session.Config.GetOption("Hostname"))
Crt.Dialog.MessageBox("Hostname2 is: " & crt.Session.Config.GetOption("Hostname"))
But these would not:
Crt.Dialog.MessageBox("Hostname1 is: " & Crt.GetScriptTab.Session.Config.GetOption("Name"))
Crt.Dialog.MessageBox("Hostname2 is: " & crt.Session.Config.GetOption("Name"))
Crt.Dialog.MessageBox("Hostname1 is: " & Crt.GetScriptTab.Session.Config.GetOption("Port"))
Crt.Dialog.MessageBox("Hostname2 is: " & crt.Session.Config.GetOption("Port"))
Crt.Dialog.MessageBox("Hostname1 is: " & Crt.GetScriptTab.Session.Config.GetOption(Port))
Crt.Dialog.MessageBox("Hostname2 is: " & crt.Session.Config.GetOption(Port))

Q2 = Why would "hostname" work but not the others?

Q3 In relation to how the GetOption method should be referenced.
GetOption method is a child of the SessionConfigurationObject.
The syntax for the SessionConfiguration object says "SessionConfiguration.Method([arglist])"
But neither of the 2 the syntax (What is plural for syntax?) which worked above appear to use this syntax.
I have assumed from the help the following:
- There is a tree structure with a text and dot notation to reference entities e.g. Node0.Node1.Node2....NodeN
- Node0 is called the root;
- The root for all SecureCRT scripting is "Crt"
- All nodes with children (i.e. all but the last node, NodeN) are known as "Objects"
- All leaf entities (last node on the tree) are either "Properties" or "Methods";
- Some "Properties" or "Methods" are "Objects" themselves (ie they have children);

Q3 = Any comment about GetOption referencing or comment/recommened reading etc about syntax appreciated.
Reply With Quote
Old 03-26-2009, 03:28 PM
slouw slouw is offline
Registered User
Join Date: Nov 2005
Posts: 166
Ok I have made some progress
Q2:I have looked in the .ini file for the session I am working on. Immediately the distinction between String type (S) and DWORD type (D) is appearant. This works a treat:
LogFileStr = Crt.Session.Config.GetOption("Log Filename")

Still appreciate any comments on Q1 and Q3....
Reply With Quote
Old 03-26-2009, 05:39 PM
miked's Avatar
miked miked is offline
Registered User
Join Date: Feb 2004
Posts: 2,039
Hi slouw,

Regarding your first question, there are a couple of ways you change the log file name. Here is a short script showing how you might do it using GetOption and SetOption.

Sub Main
    szHostname = crt.session.config.getoption("Hostname")
    szLogFilename = crt.Session.Config.Getoption("Log Filename")
    Crt.Session.Log false
    szTempStr = "TempString"
    szNewLogFilename = Replace(szLogFilename, ".log", "")
    szNewLogFilename = szNewLogFilename & " " & szTempStr & ".log"
    crt.Session.Config.Setoption "Log Filename", szNewLogFilename
    crt.Session.Log true, true
End Sub
There are quite a few things that could be done to make this more robust, but in terms of getting and setting options and especially the log filename, I hope it serves as a useful example.

I've also attached a more robust VBScript which shows another way of setting the log filename.

Regarding your question about syntax and tips on reading the syntax, I believe your comments about the syntax are correct. I tend to learn more about a language by looking at the syntax briefly then finding an example to play with extensively (testing out the methods and properties, etc.). So, my comment or tip about recommended reading is look for an example in the Help or in the forums and see what else you can do with it.

Does anybody else have comments, tips, insights or recommended reading that may help?
VanDyke Software
Technical Support
Reply With Quote

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 11:43 PM.