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 05-24-2020, 08:57 AM
mowdy mowdy is offline
Registered User
 
Join Date: Dec 2017
Posts: 1
Logs writen into txt on windows limited below 23kb

Hi there~!

I'm currently writing a script to save all logs into txt file on windows 10 with SCRT 8.5.4 (x64 build 1942);

Everything goes well until commands sent to remote server increases. I noticed that the size of txt file created by script were limited to about 23kb, I tried with VB and PHTHON, the results were accuratly the same.

I wonder if there is any limitation for file writing on Windows or Securicrt, Plz help. scripts follows:

###PYTHON###
Code:
#$language = "python"
#$interface = "1.0"

import os
import subprocess

LOG_DIRECTORY = os.path.join(
	os.path.expanduser('~'), 'Downloads','LogOutputOfSpecificCommand')

LOG_FILE_TEMPLATE = os.path.join(
	#LOG_DIRECTORY, "Command_%(NUM)s_Results.txt")
    LOG_DIRECTORY, "BABYSITTING_Results.txt")

SCRIPT_TAB = crt.GetScriptTab()

COMMANDS = [
        "xxx",
        "xxx",
        "xxx",
        "xxx",
        "xxx",
        "xxx",
        "xxx",
        "xxx",
        "xxx",
        "xxx",
        "xxx",
        "xxx",
        "xxx",
        "xxx",
        "xxx",
        "xxx",
        "xxx",
        "xxx",
        "xxx",
        "xxx",
        "xxx",
        "xxx",
        "xxx",
        "xxx",
        "xxx",
        "xxx",
        "xxx",
        "xxx",
	]

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def main():

	if not os.path.exists(LOG_DIRECTORY):
		os.mkdir(LOG_DIRECTORY)

	if not os.path.isdir(LOG_DIRECTORY):
		crt.Dialog.MessageBox(
			"Log output directory %r is not a directory" % LOG_DIRECTORY)
		return

	if not SCRIPT_TAB.Session.Connected:
		crt.Dialog.MessageBox(
			"Not Connected.  Please connect before running this script.")
		return

	SCRIPT_TAB.Screen.IgnoreEscape = True
	SCRIPT_TAB.Screen.Synchronous = True

	#while True:
	#	if not SCRIPT_TAB.Screen.WaitForCursor(1):
	#		break

	for (index, command) in enumerate(COMMANDS):
		command = command.strip()
		SCRIPT_TAB.Screen.Send(command + '\r')
		while True:
			rec = SCRIPT_TAB.Screen.WaitForStrings(["\r",":~ #",">"])
			if rec == 1:
				rowIndex = SCRIPT_TAB.Screen.CurrentRow
				prompt = SCRIPT_TAB.Screen.Get(rowIndex, 1, rowIndex, 186)
				prompt = prompt.strip()
				filep = open(LOG_FILE_TEMPLATE, 'ab+')
				filep.write(prompt + os.linesep)
				filep.flush()
				filep.close()
				continue
			elif rec == 2:
				break
			elif rec == 3:
				break
	LaunchViewer(LOG_DIRECTORY)

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def LaunchViewer(filename):
	try:
		os.startfile(filename)
	except AttributeError:
		subprocess.call(['open', filename])

main()
###VB###
Code:
#$language = "VBScript"
#$interface = "1.0"
'TEST_MOWDY_20200519
'crt.Screen.Synchronous = True

' This automatically generated script may need to be
' edited in order to work correctly.
Dim g_fso
Set g_fso = CreateObject("Scripting.FileSystemObject")

Const ForReading   = 1
Const ForWriting   = 2
Const ForAppending = 8

Dim g_szLogFile, objTab
g_szLogFile = GetMyDocumentsFolder & "\BABYSITTING_Results.txt"

Set objTab = crt.GetScriptTab

Dim g_vCommands(100)
g_vCommands(0) = "xxx"
g_vCommands(1) = "xxx"
g_vCommands(2) = "xxx"
g_vCommands(3) = "xxx"
g_vCommands(4) = "xxx"
g_vCommands(5) = "xxx"
g_vCommands(6) = "xxx"
g_vCommands(7) = "xxx"
g_vCommands(8) = "xxx"
g_vCommands(9) = "xxx"
g_vCommands(10) = "xxx"
g_vCommands(11) = "xxx"
g_vCommands(12) = "xxx"
g_vCommands(13) = "xxx"
g_vCommands(14) = "xxx"
g_vCommands(15) = "xxx"
g_vCommands(16) = "xxx"
g_vCommands(17) = "xxx"
g_vCommands(18) = "xxx"
g_vCommands(19) = "xxx"
g_vCommands(20) = "xxx"
g_vCommands(21) = "xxx"


Sub Main()
    objTab.Screen.Synchronous = True
    objTab.Screen.IgnoreEscape = True
    
    If Not objTab.session.connected then
        MsgBox "Not Connected.  Please connect before running this script."
        exit sub
    end if

    Dim szCommand, szPrompt, nRow, szLogFileName, nIndex, crlftmp
    'nRow = objTab.Screen.CurrentRow
	'nCol = objTab.Screen.CurrentColumn
    'szPrompt = objTab.screen.Get(nRow, 0, nRow, nCol - 1)
    'szPrompt = Trim(szPrompt)
    'Dim szLogFile
	Dim mytxt
	Set mytxt = g_fso.CreateTextFile(g_szLogFile)
	mytxt.close
    nIndex = 0
    Do
        szCommand = g_vCommands(nIndex)
        if szCommand = "" then Exit Do
        'szLogFile = Replace(g_szLogFile, "__NUM__", NN(nIndex + 1, 2))
        objTab.Screen.Send szCommand & chr(13)
		
			Do
					crlftmp = objTab.Screen.WaitForStrings (vbcr,":~ #",">")
					Select case	crlftmp
					case 1
					nRow = objTab.Screen.CurrentRow
					'nCol = objTab.Screen.CurrentColumn
					szPrompt = objTab.screen.Get(nRow, 1, nRow, 186)
					szPrompt = Trim(szPrompt)
					'linetmp = szPrompt
					'Dim szResult
					'szResult = objTab.Screen.ReadString(szPrompt)
					Dim objFile
					'szLogFile = g_szLogFile
					Set objFile = g_fso.OpenTextFile(g_szLogFile, ForAppending, True)
					objFile.WriteLine(szPrompt)
					objFile.Close
					case 2
					exit do
					case 3
					exit do
					End Select
			Loop
		'objFile.Close
        nIndex = nIndex + 1
    Loop
	
End Sub

Function GetMyDocumentsFolder()
    Dim myShell
    Set myShell = CreateObject("WScript.Shell")

    GetMyDocumentsFolder = myShell.SpecialFolders("MyDocuments")
End Function

'Function NN(nNumber, nDesiredDigits)
'    Dim nIndex, nOffbyDigits, szResult
'    nOffbyDigits = nDesiredDigits - len(nNumber)
'
'    szResult = nNumber
'
'    For nIndex = 1 to nOffByDigits
'        szResult = "0" & szResult
'    Next
'    NN = szResult
'End Function

Last edited by jdev; 05-26-2020 at 11:40 AM. Reason: Always use [code][/code] tags around your code for preserving indentation/spacing
Reply With Quote
  #2  
Old 05-25-2020, 10:32 AM
berdmann berdmann is offline
VanDyke Technical Support
 
Join Date: Aug 2017
Posts: 360
Hi mowdy,

I see that you have sent us an email regarding this scripting issue. I will respond to you via email.
__________________
Thanks,
--Brittney

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

Tags
txt file write size limit


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 06:58 AM.