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 09-23-2005, 04:09 PM
bdg bdg is offline
Registered User
 
Join Date: Sep 2005
Posts: 11
Cool Log Problem (crt.session.log False)

SecureCRT 5.0.3 (build 1040) on Windows XP

I am seeing this behavior when trying to dynamically start and stop logging:
#$language = "VBScript"
#$interface = "1.0"
Sub Main
CRT.Session.logFileName = ""
Call CRT.Session.Log(True)
Call CRT.Screen.Send("! Hello, World!" & vbCr)
Call CRT.Session.Log(False)
End Sub

The above will ask you where you want to put the log file (session.log) and will run correctly... except that the log file will be vacant (it'll be there, but it will not contain any text).

Run again with that last line - Call CRT.Session.Log(False) - commented out:

#$language = "VBScript"
#$interface = "1.0"
Sub Main
CRT.Session.logFileName = ""
Call CRT.Session.Log(True)
Call CRT.Screen.Send("! Hello, World!" & vbCr)
' Call CRT.Session.Log(False)
End Sub

Happy happy joy joy! The log has content... except that the file is locked until SecureCRT ends or you toggle the log via the File.Log Session menu item.

You can try everything again with a fully specified logFileName and the results will be the same.

#$language = "VBScript"
#$interface = "1.0"
Sub Main
CRT.Session.logFileName = "C:\log.txt"
Call CRT.Session.Log(True)
Call CRT.Screen.Send("! Hello, World!" & vbCr)
[ Call CRT.Session.Log(False) ]
End Sub

The key seems to be that crt.session.log False command.

Of interest, I tried a double toggle and the results were the same:
crt.session.log False
crt.session.log True
crt.session.log False
The bizarre part is that only the final crt.session.log False need be omitted in order to have the log file properly populated.
  #2  
Old 09-24-2005, 05:13 PM
erltorres erltorres is offline
Registered User
 
Join Date: Sep 2005
Posts: 4
Hi,
i had a problem with log files, more or less than you, sometimes the logfile donīt show all the lines and sometimes it put all the lines.
Try this configuration:

#$language = "VBScript"
#$interface = "1.0"
Sub Main
CRT.Session.logFileName = ""
Call CRT.Session.Log(False)
Call CRT.Session.Log(True)
crt.Sleep 1000
Call CRT.Screen.Send("! Hello, World!" & vbCr)
crt.Sleep 1000
Call CRT.Session.Log(False)
End Sub

Bye.
  #3  
Old 09-26-2005, 08:12 AM
bdg bdg is offline
Registered User
 
Join Date: Sep 2005
Posts: 11
It's NOT a Bug!

OK... it's NOT a bug!

The problem is that there is a delay between sending text to the Device-under-Test (DuT) and SecureCRT receiving the echo. A script such as the one shown in the initial post does not provide enough of a delay between the CRT.Screen.Send and CRT.Session.Log(False) for the text to be echoed.

time
|
+-> CRT.Screen.Send "! Hello, World!" & vbCr
| sends "! Hello, World!\lineend" to DuT
|
+-> CRT.Session.Log False
| turns off logging
|
+-> "! Hello, World!\lineend"
received from DuT but is not logged because logging is disabled

This is not something that SecureCRT, by itself, can completely correct. Even affirming (setting to True) the CRT.Screen.synchronous property is not enough to ensure that the echo has occurred. The only tools available are the CRT.Application.Sleep, CRT.Screen.WaitForCursor, CRT.Screen.WaitForString and CRT.Screen.WaitForStrings methods... imperfect tools but about all that can be done from ouside the DuT.

Advice: use CRT.Application.Sleep only when necessary as it can "ensure" that your stimulus/test script will run slowly- sleeping after every CRT.Screen.Send results in a very lethargic run.
---
Requests for Enhancements:
1- CRT.Session.logFileName="" followed by Call CRT.Session.Log(True) presents a dialog that asks the attending user to specify the file to be used for the log. However, the property CRT.Session.logFileName is not set in this case; it still contains the vacant string ("").

2- There are no state properties: CRT.Session.isLogging, CRT.Session.isAppending and CRT.Session.isRaw ("mah gran'pappy always tol' me to provide a way to interrogate anything I set...").
  #4  
Old 03-15-2006, 09:51 AM
bdg bdg is offline
Registered User
 
Join Date: Sep 2005
Posts: 11
Unhappy Restarting a Log

Sorry to reopen this thread; thanks for your tolerance.

I am trying to restart logging after disconnecting and reconnecting to a target.
Here is an abbreviated snippet of code (the actual code, redundant synchrony settings and all, is attached as a .TXT file):
Code:
   CRT.Screen.synchronous = True
   CRT.Session.Connect "/telnet targetIP 23"
   CRT.Screen.WaitForString("ogin:", 3)
   CRT.Screen.Send identity & vbCr
   CRT.Screen.WaitForString("assword:", 1)
   CRT.Screen.Send password & vbCr
...wait awhile...
CRT.Session.logFileName = n CRT.Session.Log True, False, False
...wait awhile...
CRT.Screen.Send "# Logged text 1" & vbCr
...wait awhile...
CRT.Session.Disconnect CRT.Session.Connect "/telnet targetIP 23" CRT.Screen.WaitForString("ogin:", 3) CRT.Screen.Send identity & vbCr CRT.Screen.WaitForString("assword:", 1) CRT.Screen.Send password & vbCr
...wait awhile...
CRT.Session.Log True, True, False
...wait awhile...
CRT.Screen.Send "# Logged text 2" & vbCr
The text in the log file is:
Code:
-bash-2.05b$ # Logged text 2
-bash-2.05b$ logout
What happened to the first line (# Logged text 1)?
Attached Files
File Type: txt logTest.txt (2.3 KB, 328 views)
__________________
Laurens Cornelis Boudewijn de Graaf
(maybe) my Great Great Great Great Grandfather...
  #5  
Old 03-15-2006, 12:30 PM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,040
Hi bdg,

Your script ran perfectly for me - it logged the first line.

Here's the log file it generated:
C:\>type myLog.log
$ # Logged text 1
#: Command not found.
$ # Logged text 2
#: Command not found.
$ logout
If you add a short sleep before sending the first line, does the first line get logged?
Code:
CRT.Session.Log True, False, False
CRT.Sleep 500   ' sleep 500 milliseconds, probably much too long
CRT.Screen.Send "# Logged text 1" & vbCr
__________________
Mike
VanDyke Software
Technical Support
[http://www.vandyke.com/support]
  #6  
Old 03-15-2006, 01:53 PM
bdg bdg is offline
Registered User
 
Join Date: Sep 2005
Posts: 11
No joy... So far, I'm generating separate log files for each session. However, I'd sure like to be able to generate one file.

Here's the new test code (a little smaller and with CRT.Sleep 1000 statements):
Code:
#$language = "VBScript"
#$interface = "1.0"
Option Explicit

Sub Main
   Dim a, l, p

   CRT.Screen.synchronous = True
   CRT.Session.Disconnect

   '===
   ' Acquire the target's address, login identity
   ' and password.
   '- -
   a = Trim(InputBox("Please enter the target's IP address"))
   If a = "" Then Exit Sub
   l = Trim(InputBox("Please enter the login identity"))
   If l = "" Then Exit Sub
   p = Trim(InputBox("Please enter the password"))
   If p = "" Then Exit Sub

   '===
   ' Perform the first session.
   '- -
   CRT.Sleep 1000
   CRT.Session.Connect "/telnet " & a & " 23"
   CRT.Screen.WaitForString "ogin:", 3
   CRT.Screen.Send l & vbCr
   CRT.Screen.WaitForString "assword:", 1 
   CRT.Screen.Send p & vbCr
   Do While CRT.Screen.WaitForCursor(1)
   Loop
   CRT.Session.logFileName = "C:\myLog.log"
   CRT.Session.Log True, False, False
   CRT.Sleep 1000
   CRT.Screen.Send "echo 'Hello, World!'" & vbCr
   Do While CRT.Screen.WaitForCursor(1)
   Loop
   CRT.Sleep 1000
   CRT.Session.Disconnect

   '===
   ' Perform the second session.
   '- -
   CRT.Sleep 1000
   CRT.Session.Connect "/telnet " & a & " 23"
   CRT.Screen.WaitForString "ogin:", 3
   CRT.Screen.Send l & vbCr
   CRT.Screen.WaitForString "assword:", 1 
   CRT.Screen.Send p & vbCr
   Do While CRT.Screen.WaitForCursor(1)
   Loop
   CRT.Session.logFileName = "C:\myLog.log"
   CRT.Session.Log True, True, False
   CRT.Sleep 1000
   CRT.Screen.Send "echo 'Hello, again!'" & vbCr
   Do While CRT.Screen.WaitForCursor(1)
   Loop
   CRT.Sleep 1000
   CRT.Session.Disconnect
End Sub
Here's the log:
Code:
-bash-2.05b$ echo 'Hello, again!'
Hello, again!
Here's the SecureCRT build:
Version 5.0.3 (build 1040) - Official Release - September 8, 2005

BtW- I notice that whatever disables the logging (CRT.Session.Disconnect AND CRT.Session.Connect, by the way), clears CRT.Session.logFileName.
__________________
Laurens Cornelis Boudewijn de Graaf
(maybe) my Great Great Great Great Grandfather...
  #7  
Old 03-17-2006, 08:34 AM
bdg bdg is offline
Registered User
 
Join Date: Sep 2005
Posts: 11
Red face THE SOLUTION! Use the latest release (duh)!

First of all, my thanks to the Van Dyke folk (especially Michael Decker) for really hanging in there to help me shoot this one!

The answer is to ensure that you are running the latest software. I finally found our company's license key and installed 5.0.5. Restarting logging now works properly.

Here is a test script:
Code:
#$language = "VBScript"
#$interface = "1.0"
Option Explicit
Sub Main
	Dim l
	CRT.Screen.synchronous = True
	l = Trim(InputBox("Please enter the complete path for the log file"))
	If l = "" Then Exit Sub
	CRT.Session.logFileName = l
	CRT.Session.Log True, False, True
	CRT.Screen.Send "echo 'Logging to " & l & "'" & vbCr
	CRT.Screen.WaitForString "$", 3
	CRT.Screen.Send "date" & vbCr
	CRT.Screen.WaitForString "$", 3
	CRT.Session.Log False
	CRT.Screen.Send "echo 'This should not be logged'" & vbCr
	CRT.Screen.WaitForString "$", 3
	CRT.Screen.Send "date" & vbCr
	CRT.Screen.WaitForString "$", 3
	CRT.Session.Log True, True, True
	CRT.Screen.Send "echo 'Appending to " & l & "'" & vbCr
	CRT.Screen.WaitForString "$", 3
	CRT.Screen.Send "date" & vbCr
	CRT.Screen.WaitForString "$", 3
End Sub
Here is the generated log file:
Code:
echo 'Logging to C:\logTest.txt'
Logging to C:\logTest.txt
-bash-2.05b$ date
Fri Mar 17 10:26:34 EST 2006
-bash-2.05b$ echo 'Appending to C:\logTest.txt'
Appending to C:\logTest.txt
-bash-2.05b$ date
Fri Mar 17 10:26:35 EST 2006
-bash-2.05b$
Here is a screen shot:
Code:
Red Hat Enterprise Linux AS release 3 (Taroon)
Kernel 2.4.21-4.ELsmp on an i686
login: bdg
Password: 
Last login: Fri Mar 17 10:16:07 from bti7j3rx11
-bash-2.05b$ echo 'Logging to C:\logTest.txt'
Logging to C:\logTest.txt
-bash-2.05b$ date
Fri Mar 17 10:26:34 EST 2006
-bash-2.05b$ echo 'This should not be logged'
This should not be logged
-bash-2.05b$ date
Fri Mar 17 10:26:35 EST 2006
-bash-2.05b$ echo 'Appending to C:\logTest.txt'
Appending to C:\logTest.txt
-bash-2.05b$ date
Fri Mar 17 10:26:35 EST 2006
-bash-2.05b$ 
-bash-2.05b$
Some things I discovered that are either not in the documentation or I'm just too dumb to find them:
1- Assume that both CRT.Session.Disconnect and CRT.Session.Connect disable logging,
effectively issuing CRT.Session.Log False
2- Some releases vacate CRT.Session.logFileName (set it to "")
...maybe...
__________________
Laurens Cornelis Boudewijn de Graaf
(maybe) my Great Great Great Great Grandfather...
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 07:13 AM.