VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   Scripting (https://forums.vandyke.com/forumdisplay.php?f=14)
-   -   Log Session doesn't prompt for file name any more (https://forums.vandyke.com/showthread.php?t=10601)

emailsbecker 07-30-2012 02:03 AM

Log Session doesn't prompt for file name any more
 
Hi all. I created the code below to check if logging is currently turned on so I could give a user a choice of options instead of cutting off their log against their wishes. But after running this script I've discovered that if I go to File -> Log Session to manually start a new log I'm no longer asked where I want the file to be saved or what I want the log to be named, it automatically uses the time stamp below and hostname discovered on the last run of the script. Is there any way to stop this? I want to be able to record other logs and manually choose their names and locations outside of the situation where I would be running this script.


Code:

sub Main

  crt.Screen.Synchronous = True

  ' If folder doesn't exist create it
  '
  Dim filesys, newfolder
  set filesys=CreateObject("Scripting.FileSystemObject")
  If  Not filesys.FolderExists("C:\00 - SecureCRT Logfiles") Then
    newfolder = filesys.CreateFolder ("C:\00 - SecureCRT Logfiles")
  End If

  ' Check to see if logging is enabled
  '
  If crt.Session.Logging <> False Then

    Result = MsgBox ("Session logging is already enabled." & vbcr & vbcr & "Click 'YES' to use your current log." & vbcr & "Click 'NO' to end the current log and create a new one for this script." & vbcr & "Click 'CANCEL' to terminate this script without doing anything.", _
    vbYesNoCancel + vbExclamation + vbDefaultButton3 + vbApplicationModal + vbMsgBoxSetForeground, _
      "Session Logging Decision Needed")

    If Result = vbYes Then crt.Sleep 1000 End If
    If Result = vbNo Then Call StartLog        End If
    If Result = vbCancel Then Exit Sub End If
 
  Else Call StartLog
 
  End If

'
' body of script here
'

End Sub



Sub StartLog

  ' Get hostname to be used in the logfile filename
  '
  crt.Screen.Send "show system" & vbCr : crt.Screen.WaitForString vbCr
  strHNPre = crt.Screen.ReadString ("#")
  strHN = Split(Mid(strHNPre, 32), vbcrlf)(0)
 
  ' Set logfile name & turn on logging
  '
  logfile = "C:\00 - SecureCRT Logfiles\%Y.%M.%D-%h.%m.%s-" & strHN & ".log"
  ' msgbox "logfile name will be " & MyDate & "-" & strHN & ".log"
  crt.Session.LogFileName = logfile
  crt.Session.Log False
  crt.Session.Log True

End Sub


bgagnon 07-30-2012 12:36 PM

Hi emailsbecker,

When you choose File / Log Session, if the Terminal / Log File category of SecureCRT's Session Options is configured with a valid log path, it will be used unless the Prompt for filename option is enabled

However, the user will always be prompted for a log file name if the session option Log file name is blank.

This line in your code changes Session Options so that the log file name is no longer blank:

Code:

crt.Session.LogFileName = logfile
One way to restore the blank log file name is shown in the code sample below.

This has the added benefit that if the user does already have a custom log file name, running your script will not wipe out their configuration.

Code:

strOrigLogFilename = crt.Session.Config.GetOption("Log Filename")
crt.Session.LogFileName = logfile
crt.Session.Log False
crt.Session.Log True
crt.Session.Config.SetOption "Log Filename", strOrigLogFilename

The above has been tested in SecureCRT version 7.0. If you are running an older version of SecureCRT, you may need to upgrade to use this solution.

emailsbecker 07-31-2012 07:17 AM

Hi Brenda,

I'm using 6.1.1 (build 383) and it worked for me. Thanks!

~Steve

bgagnon 07-31-2012 09:00 AM

Hi Steve,

Thanks for the update.

You can check your upgrade eligibility status here.


All times are GMT -6. The time now is 06:07 AM.