View Single Post
Old 11-10-2016, 01:03 AM
andrisetia andrisetia is offline
Registered User
Join Date: Nov 2016
Posts: 1
Output not generated on WriteLine

I run this on CMD

"C:\Program Files\VanDyke Software\SecureCRT\SecureCRT.exe" /S "New_IXXXX\BXXX\Hxxxx" /script "E:\Automation\ReadScreen.vbs"

ReadScreen.vbs script:
#$language = "VBScript"
#$interface = "1.0"

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 & "\Command#__NUM___Results.txt"

Set objTab = crt.GetScriptTab

Dim g_vCommands(100)
g_vCommands(0) = "sh"

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

nRow = objTab.Screen.CurrentRow
szPrompt = objTab.screen.Get(nRow, 0, nRow, objTab.Screen.CurrentColumn - 1)
szPrompt = Trim(szPrompt)

Dim szLogFile
nIndex = 0
szCommand = Trim(g_vCommands(nIndex))

' If the command is empty, then we should be done issuing commands
' (there's nothing else in our command array g_vCommands)
if szCommand = "" then Exit Do

' Set up the log file for this specific command
szLogFile = Replace(g_szLogFile, "__NUM__", NN(nIndex + 1, 2))

' Send the command text to the remote
objTab.Screen.Send szCommand & vbcr

' Wait for the command to be echo'd back to us.
objTab.Screen.WaitForString vbcr, 1
objTab.Screen.WaitForString vblf, 1

Dim szResult
szResult = objTab.Screen.ReadString(szPrompt)

Dim objFile
Set objFile = g_fso.OpenTextFile(szLogFile, ForWriting, True)

' If you don't want the command logged along with the results, comment
' out the very next line
objFile.WriteLine "Results of command: " & szCommand

' Write out the results of the command to our log file
objFile.WriteLine szResult

' Close the log file

' Move on to the next command in our command array g_vCommands
nIndex = nIndex + 1

End Sub

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

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

Function NN(nNumber, nDesiredDigits)
' Normalizes a single digit number to have nDesiredDigits 0s in front of it
Dim nIndex, nOffbyDigits, szResult
nOffbyDigits = nDesiredDigits - len(nNumber)

szResult = nNumber

For nIndex = 1 to nOffByDigits
szResult = "0" & szResult
NN = szResult
End Function

My question why is on the text file the

' Write out the results of the command to our log file
objFile.WriteLine szResult

is not writing anything on the output Command#01_Results.txt

instead only objFile.WriteLine "Results of command: " & szCommand
is writen on the file.

How to get the screen result of sh is writen on the file?

any idea
Reply With Quote