Welcome to the VanDyke Software Forums

Join the discussion today!

Go Back   VanDyke Software Forums > Scripting


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


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

# $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.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.
Reply With Quote
Old 02-17-2020, 11:16 AM
berdmann berdmann is offline
VanDyke Technical Support
Join Date: Aug 2017
Posts: 441
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:
# $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

End Sub
Is this information helpful?

VanDyke Software
Technical Support
(505) 332-5730
Reply With Quote

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 11:21 PM.