Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1  
Old 10-27-2020, 09:43 AM
Rhudi's Avatar
Rhudi Rhudi is offline
Registered User
 
Join Date: Jul 2013
Location: Greenville, SC
Posts: 90
Custom Log Data not working

I have a script that works very well to establish AdHoc connections to devices. This script has an added bonus of trying SSH, then TELNET. Once either of those is connected, I have code as follows (all variables are properly defined):
Code:
            Select Case bConnected
                Case True ' Connected
                    UserName = env("USERNAME")
                    UserProf = env("USERPROFILE")
                    objTab.Caption = strConnectType & strShortHostName
                    crt.Session.SetStatusText("Connected: " & strConnectType & strShortHostName)
                      Set objTab = crt.GetScriptTab
                      Set objConfig = objTab.Session.Config
                      objConfig.SetOption "Custom Log Message Each Line", "%h:%m:%s | "                    
                    crt.Session.LogFileName =  UserProf & "\SecureCRT Logs\" & UserName & "\%Y-%M-%D.%h.%m - " & strShortHostName & " -- (" & UserName & ").log"
                    crt.Session.Log True
                Case False ' Not Connected
                    crt.Dialog.MessageBox "Try again later:" & vbCrLf & strShortHostName
            End Select
The problem is, this line has no visible impact:
objConfig.SetOption "Custom Log Message Each Line", "%h:%m:%s | "

I do get my log file in the specified folder, but the lines have no time stamp.

I am using:
Version 8.3.4 (x64 build 1699) - Official Release - July 12, 2018
and have no ability to upgrade.

Last edited by Rhudi; 10-27-2020 at 10:30 AM. Reason: minor correction
  #2  
Old 10-27-2020, 10:53 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,494
Hi Rhudi,

You wrote that you are establishing ad hoc connections. Is that now in a new tab, that is not the script tab? Because within your Case statement you set the tab object to again be the script tab. Instead you would want to reference your new tab object, where the connection was established with ConnectInTab() I assume.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
  #3  
Old 10-27-2020, 12:57 PM
Rhudi's Avatar
Rhudi Rhudi is offline
Registered User
 
Join Date: Jul 2013
Location: Greenville, SC
Posts: 90
There are numerous steps in this script that are unrelated to the logging. Basically, I am using a command line to pass arguments to a new tab. Once that tabs is running, it connects to a pre-defined session. That host is a Linux system. The next part of my script confirms the target host is valid by doing an nslookup on the name passed. That part works as expected. Still within the Linux host, I ssh to the target device (If that connection times out, it will try a telnet). I will get to the target device with no problem. My log file opens with no trouble. I just don't get the time stamp on each line.

I believe you have pointed me in the right direction. The script is running within the tab I've started. It may very well be that I'm not telling the right thing to log the time per line.
  #4  
Old 10-27-2020, 01:33 PM
Rhudi's Avatar
Rhudi Rhudi is offline
Registered User
 
Join Date: Jul 2013
Location: Greenville, SC
Posts: 90
I believe I made an error by saying "AdHoc".

Strictly speaking, these are not AdHoc. I'm using an externally scripted shell command to launch a pre-defined Linux Host Session in SecureCRT. One of the command line arguments is my script.

That will start SecureCRT if it is not running, or start a new tab if it is. That new tab is where my script is running.

I have logging options set in the defined session, but they do not seem to work. Plus, I don't need any of the Linux part logged. I only want to log after the Linux has connected to the actual end device.

I do get a log, I get it when I want. I just don't get the per-line time stamp I'd like to have.
  #5  
Old 10-27-2020, 03:08 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,494
Hi Rhudi,

I still cannot replicate your results. Are you sure you are going into the correct Case statement with the log each line configuration?

Here were my steps which is a simplified version of what I understand your objective to be.

My script is:
Code:
Set objTab = crt.GetScriptTab
Set objConfig = objTab.Session.Config
objConfig.SetOption "Custom Log Message Each Line", "%h:%m:%s | "
objTab.Session.LogFileName =  "C:\Temp\Ubuntu_%Y-%M-%D.%h.%m.log"
  • From CMD run SecureCRT /Script "path_to_script" /S "MyUbuntuSession"
  • So now I am authenticated and sitting at the prompt, I enable Log Session from File menu
  • Run a few commands
  • Choose Log Session again to stop logging
  • Open my log file named Ubuntu_2020-10-27.12.52.log and this is the contents:
12:52:16 | user@ubuntu:~$ uptime
12:52:16 | 13:52:16 up 17 days, 22:11, 2 users, load average: 0.06, 0.25, 0.20
12:52:17 | user@ubuntu:~$ pwd
12:52:17 | /home/vdt-csg

I have tested this both in the official release and v8.3.4 and it works in both versions.

You will need to post explicit steps and the entire script with sensitive data redacted or send it to support@vandyke.com with Attn Brenda - Forum Thread #14326 in the subject line.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
  #6  
Old 10-27-2020, 10:20 PM
Rhudi's Avatar
Rhudi Rhudi is offline
Registered User
 
Join Date: Jul 2013
Location: Greenville, SC
Posts: 90
I deeply appreciate your time helping me with this.

Here is the relevant (I think) section:
Code:
Select Case bConnected
    Case True ' Connected
        UserName = env("USERNAME")
        UserProf = env("USERPROFILE")
        objTab.Caption = strConnectType & strShortHostName
        crt.Session.SetStatusText("Connected: " & strConnectType & strShortHostName)
        Call CLS
        objTab.Session.Log False
        Set objConfig = objTab.Session.Config
        objConfig.SetOption "Custom Log Message Each Line", "%h:%m:%s | "
        objTab.Session.LogFileName =  UserProf & "\SecureCRT Logs\" & UserName & "\%Y-%M-%D.%h.%m - " & strShortHostName & " -- (" & UserName & ").log"
        objTab.Session.Log True
    Case False ' Not Connected
        crt.Dialog.MessageBox "Try again later:" & vbCrLf & strShortHostName
End Select
I had "crt.Session" for several lines in there and changed them to "objTab.Session".

Is "objTab.Session.Log True/False" the correct way to toggle logging?

I did an experiment... I did what you did, using the File Menu to Toggle Logging. At that point, the lines are tagged as expected.

So, the way I am trying to enable logging with the script is the culprit.

Last edited by Rhudi; 10-27-2020 at 10:23 PM. Reason: Additional info
  #7  
Old 10-28-2020, 12:38 PM
Rhudi's Avatar
Rhudi Rhudi is offline
Registered User
 
Join Date: Jul 2013
Location: Greenville, SC
Posts: 90
This fixes it:

objTab.Session.LogUsingSessionOptions

Last edited by Rhudi; 10-28-2020 at 12:43 PM. Reason: SOLVED
  #8  
Old 10-28-2020, 12:51 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,494
Hi Rhudi,

I replied to your email.

The answer is yes, because the change you apply with SetOption() changes Session Options for the session launched via command-line. That's the only way to apply the per line config options since there is not a command-line option for it.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
  #9  
Old 10-28-2020, 01:49 PM
Rhudi's Avatar
Rhudi Rhudi is offline
Registered User
 
Join Date: Jul 2013
Location: Greenville, SC
Posts: 90
[SOLVED]

Here is the relevant section that now works as expected:
Code:
Select Case bConnected
    Case True ' Connected
        UserName = env("USERNAME")
        UserProf = env("USERPROFILE")
        objTab.Caption = strConnectType & strShortHostName
        objTab.Session.SetStatusText("Connected: " & strConnectType & strShortHostName)
        Call CLS
        objTab.Session.Log False
        objTab.Session.Config.SetOption "Custom Log Message Each Line", "%h:%m:%s | "
        objTab.Session.LogFileName =  UserProf & "\SecureCRT Logs\" & UserName & "\%Y-%M-%D.%h.%m - " & strShortHostName & " -- (" & UserName & ").log"
        objTab.Session.LogUsingSessionOptions
    Case False ' Not Connected
        crt.Dialog.MessageBox "Try again later:" & vbCrLf & strShortHostName
End Select
This is what fixed it:
Code:
objTab.Session.LogUsingSessionOptions
Closed Thread


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 08:50 AM.