Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 02-15-2020, 07:11 AM
mircea mircea is offline
Registered User
 
Join Date: Feb 2020
Posts: 1
Log output empty

Hello,

I am trying to log only parts of the session and I am using the following script:

Code:
# $language = "VBScript"
# $interface = "1.0"

Const ForReading = 1
Const ForWriting = 2

logNam = crt.Dialog.Prompt ("Please enter Pre/Post:")

prompt = crt.Screen.Get(crt.Screen.CurrentRow, 1, crt.Screen.CurrentRow, 80)
nodeName = Left(prompt, InStr(prompt, ">") - 1)

If crt.Session.Logging Then
 ' Turn off logging before setting up our script's
 ' logging...
 crt.Session.Log False
End If

crt.Session.LogFileName = "Z:\CRT Logs\Healthchecks\" & logNam & "-HC-" & nodeName & "-%h-%m-%D-%M-%Y.log"

crt.Session.LogUsingSessionOptions

crt.Screen.Send "xxxx" & vbcr
crt.Screen.Send "xxxx" & vbcr


crt.Session.Log False
For some reason my log files are created but empty.

Thank you in advance.
Mircea
Reply With Quote
  #2  
Old 02-17-2020, 10:16 AM
berdmann berdmann is offline
VanDyke Technical Support
 
Join Date: Aug 2017
Posts: 319
Hello Mircea,

The log file is empty because your script completes before the remote has had time to echo back the command and it's output.

You will need to first set the screen to Synchronous:
crt.Screen.Synchronous = True
You all also need to slow down the rate that your commands are being sent to the remote. One way to accomplish this is to wait for your prompt before sending each subsequent command:

crt.Screen.WaitForString "prompt", 5
Please refer to the following script example:
Code:
# $language = "VBScript"
# $interface = "1.0"

' This script sets a specific logfile, enables logging then connects
' to a server. After capturing the output of a command to the logfile
' logging is disabled and it disconnects.

Sub Main

  ' Turn on synchronous mode while performing Send/Wait sequences
  ' so no input is missed.
  '
  crt.Screen.Synchronous = True

  ' Connect using a pre-defined session that automatically logs you in.
  '
  crt.Session.Connect "/s SessionName"

  ' Wait for my unix login prompt or for 5 seconds whichever
  ' comes first.
  '
  crt.Screen.WaitForString "@ubu18:~$", 5

  ' Set the name of the log file name "YYMMDD.log"
  '
  Dim logfile
  logfile = "C:\Users\user\Desktop\YYMMDD.log"
  crt.Session.LogFileName = logfile

  ' Enable logging
  '
  crt.Session.Log True

  ' Send a unix command. The output of the command will
  ' be captured to the logfile.
  '
  crt.Screen.Send "date" & vbCr

  ' Wait again for my login prompt or 5 seconds
  '
  crt.Screen.WaitForString "@ubu18:~$", 5

  ' Turn off synchronous mode
  crt.Screen.Synchronous = false

  ' Stop logging and disconnect.
  '
  crt.Session.Log False
  crt.Session.Disconnect

End Sub
Is this information helpful?
__________________
Thanks,
--Brittney

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


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 09:04 PM.