Welcome to the VanDyke Software Forums

Join the discussion today!

Go Back   VanDyke Software Forums > Scripting

Thread Tools Rate Thread Display Modes
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 BXX_DXXXX.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 BXX_DXXXX.sh is writen on the file?

any idea
Reply With Quote
Old 11-10-2016, 09:41 AM
bgagnon bgagnon is offline
VanDyke Technical Support
Join Date: Oct 2008
Posts: 4,548
Hi andrisetia,

Your "command" is executing a shell script on the remote server, correct?

What does your shell script do?

As an FYI, your SecureCRT command-line syntax is out of order. Standard options should always precede protocol-specific options as outlined in the SecureCRT Help topic Using the Software / Command-Line Options / Overview of Command-Line Options:

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

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

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