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 07-30-2012, 02:03 AM
emailsbecker emailsbecker is offline
Registered User
 
Join Date: Apr 2011
Posts: 74
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
Reply With Quote
  #2  
Old 07-30-2012, 12:36 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,633
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.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 07-31-2012, 07:17 AM
emailsbecker emailsbecker is offline
Registered User
 
Join Date: Apr 2011
Posts: 74
Hi Brenda,

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

~Steve
Reply With Quote
  #4  
Old 07-31-2012, 09:00 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,633
Hi Steve,

Thanks for the update.

You can check your upgrade eligibility status here.
__________________
Thanks,
--Brenda

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

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