Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 12-11-2017, 05:25 AM
Zander Zander is offline
Registered User
 
Join Date: Oct 2016
Posts: 11
Logging variables

Hi all,

I've currently got a script setup (with a lot of help from other forum members!) that I use multiple times every day. The function of the script is simple, I copy an IP address from a spreadsheet / wherever and then run the script on a server - The script will then login to a Cisco router and run some commands for me!

In the last week or so I've written in the functionality so that I can rename the CRT tab to the hostname of the Cisco router and I've also written in the ability for the script to change the log name to the router that I'm on!

I am however having some issues! I've got the logging sorted but I'm lacking some functionality. When setting up a pre-defined session in SecureCRT you can choose logging options such as "Upon connect:", "Upon disconnect:" & "On each line:"

What I would like to know, is there the ability to set these variables in a script so that once I start the new log I can see the connection times etc.?

For context here is the excerpt from my script...

Code:
'Setup logging using the CPE hostname
        If crt.Session.Logging Then
            ' Turn off logging before setting up individual CPE
            ' logging...
            crt.Session.Log False
        End If
        'Set the file path + Year & Month & then add the date 
		'to the beginning + the CPE hostname
		strCPELogName = ("C:\CRT\Logging\%Y\%M\%D_" & strHostname & ".txt")
        crt.Session.LogFileName = strCPELogName
		'Turn Logging on - True,True = On & append to make sure you don't
		'overwrite an old log if you log onto the CPE twice in one day
        crt.session.Log True,True
Thank you very much in advance!
(P.S. I'm unsure why my code on the forum doesn't have the correct / normal colouring so apologies if it's hard to read!)
Reply With Quote
  #2  
Old 12-11-2017, 08:12 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
Hi Zander,

Yes, since these are options found in Session Options, you can use the SetOption method available to the SessionConfiguration object. (See SecureCRT's Help topic Scripting / Script Objects Reference / SessionConfiguration Object.)

The three particular entries (in session INI files) that are responsible for custom logging are:
Code:
S:"Custom Log Message Connect"=
S:"Custom Log Message Disconnect"=
S:"Custom Log Message Each Line"=
The format of SetOption method is, for example (in VBScript):
Code:
objConfig.SetOption "Custom Log Message Connect", "====== Session Connected! ======"
Zander,
You do *not* need the line-ending. Sorry. I removed & vbcrlf from line above.


With the "tab-safe" prerequisites, such as:
Code:
Set objTab = crt.GetScriptTab
Set objConfig = objTab.Session.Config
__________________
Thanks,
--Brenda

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

Last edited by bgagnon; 12-12-2017 at 08:57 AM. Reason: removed line ending
Reply With Quote
  #3  
Old 12-12-2017, 07:52 AM
Zander Zander is offline
Registered User
 
Join Date: Oct 2016
Posts: 11
Quote:
Originally Posted by bgagnon View Post
Hi Zander,

Yes, since these are options found in Session Options, you can use the SetOption method available to the SessionConfiguration object. (See SecureCRT's Help topic Scripting / Script Objects Reference / SessionConfiguration Object.)

The three particular entries (in session INI files) that are responsible for custom logging are:
Code:
S:"Custom Log Message Connect"=
S:"Custom Log Message Disconnect"=
S:"Custom Log Message Each Line"=
The format of SetOption method is, for example (in VBScript):
Code:
objConfig.SetOption "Custom Log Message Connect", "====== Session Connected! ======"
Zander,
You do *not* need the line-ending. Sorry. I removed & vbcrlf from line above.


With the "tab-safe" prerequisites, such as:
Code:
Set objTab = crt.GetScriptTab
Set objConfig = objTab.Session.Config
Thank you very much for your response Brenda Please excuse my ignorance but I'm not sure where to look for the SecureCRT Help topic? I've been using the very handy PDF for a few things but can't seem to find anything around this topic in there?

I've attempted to add in the connection message into my script but I'm still not seeing anything in the log file - Am I putting those lines in the right place in the script?

Code:
'Set the file path + Year & Month & then add the date 
		'to the beginning + the CPE hostname
		strCPELogName = ("C:\CRT\Logging\%Y\%M\%D_" & strHostname & ".txt")
        crt.Session.LogFileName = strCPELogName
		'Turn Logging on - True,True = On & append to make sure you don't
		'overwrite an old log if you log onto the CPE twice in one day
		crt.session.Log True,True
		Set objConfig = objTab.Session.Config
		objConfig.SetOption "Custom Log Message Connect", "====== Session Connected! ======" & vbcrlf
Thanks in advance

Last edited by bgagnon; 12-12-2017 at 08:58 AM. Reason: Removed line ending from quoted code
Reply With Quote
  #4  
Old 12-12-2017, 08:55 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
Hi Zander,

What version of SecureCRT are you using?

I am not sure of the PDF you referenced. One can be obtained by contacting us, but it's not available on the website as far as I know.

The Help topics are accessed from Help menu item, then choose Help Topics. Or, the ? icon on the toolbar. See attached.

From the Contents tab, you will see the main level topic of Scripting. If you expand the "+", then Script Objects Reference, etc.

The new code is not placed correctly. You would need to make the change to the session configuration *before* you enable logging. I can't tell you exactly where it goes because I don't know the complete script, but definitely *before* you re-enable logging with the custom CPE name.
Attached Images
File Type: png forum_zander_HelpFile.png (90.6 KB, 2241 views)
__________________
Thanks,
--Brenda

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

Tags
log file , logging , script

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:36 AM.