|
#1
|
|||
|
|||
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 (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!) |
#2
|
|||
|
|||
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"= Code:
objConfig.SetOption "Custom Log Message Connect", "====== Session Connected! ======" 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 |
#3
|
|||
|
|||
Quote:
![]() 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 ![]() Last edited by bgagnon; 12-12-2017 at 08:58 AM. Reason: Removed line ending from quoted code |
#4
|
|||
|
|||
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.
__________________
Thanks, --Brenda VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
![]() |
Tags |
log file , logging , script |
Thread Tools | |
Display Modes | Rate This Thread |
|
|