Combining data from two consecutive screens
Hey all, Kind of new to scripting, and after reading some of these posts, determined you guys are the best source for help. I am trying to combine data from multiple consecutive screens into a csv file using the get2() command. I am needing to capture (x)rows of data, Hit the Enter key and capture the same rows on the following screen then output both sets of data stacked over each other to the CSV file. I have one page working, and I am getting nowhere trying to figure out the next page. Any help would be greatly appreciated. Here is my code below.
#$language = "VBScript"
#$interface = "1.0"
' If non-whitespace text is selected within the terminal screen, the user
' will be prompted for a location + filename in which to store the selected
' text as a CSV file. Multiple space characters within the data will be
' converted to a single comma character.
' - How to use the Screen.Selection property new to SecureCRT 6.1 to access
' text selected within the terminal window.
' - How to use the Scripting.FileSystemObject to write data to a
' text file.
' - How to use RegExp's Replace() method to convert sequential space
' characters into a single comma character.
' - One way of determining if the script is running on Windows XP or not.
' - One way of displaying a file browse/open dialog in Windows XP
' g_nMode is used only if the user specifies a file that already exists, in
' which case the user will be prompted to overwrite the existing file, append
' to the existing file, or cancel the operation.
Const ForWriting = 2
Const ForAppending = 8
' Be "tab safe" by getting a reference to the tab for which this script
' has been launched:
Set objTab = crt.GetScriptTab
Set g_shell = CreateObject("WScript.Shell")
Set g_fso = CreateObject("Scripting.FileSystemObject")
' Capture the selected text into a variable. The 'Selection' property
' is available in SecureCRT 6.1 and later. This line of code will cause
' an error if launched in a version of SecureCRT earlier than 6.1.
'++strSelection = objTab.Screen.Selection
readline = crt.Screen.Get2(4,1, 21,crt.Screen.Columns)
'items = Split( readline, ":", -1 )
'readline = Split(screenrow, vbcrlf)
'For nIndex = 1 To UBound(strSelection)
'MsgBox "Line #" & nIndex & ": " & strSelection(nIndex - 1)
' Check to see if the selection really has any text to save... we don't
' usually want to write out nothing to a file.
'++If Trim(strSelection) = "" Then
'++crt.Dialog.MessageBox "Nothing to save!"
strFilename = g_shell.SpecialFolders("MyDocuments") & _
"\" & crt.Session.RemoteAddress & "-SelectedText.csv"
strFilename = BrowseForFile(strFilename)
If strFilename = "" Then Exit Sub
' Do some sanity checking if the file specified by the user already
If g_fso.FileExists(strFilename) Then
nResult = crt.Dialog.MessageBox( _
"Do you want to replace the contents of """ & _
strFilename & _
""" with the selected text?" & vbcrlf & vbcrlf & _
vbtab & "Yes = overwrite" & vbcrlf & vbcrlf & _
vbtab & "No = append" & vbcrlf & vbcrlf & _
vbtab & "Cancel = end script" & vbcrlf, _
"Replace Existing File?", _
Select Case (nResult)
g_nMode = ForWriting
g_nMode = ForAppending
g_nMode = ForWriting
' Automatically append a .csv if the filename supplied doesn't include
' any extension.
If g_fso.GetExtensionName(strFilename) = "" Then
strFilename = strFilename & ".csv"
' Replace instances of one or more space characters with a comma. Use
' the VBScript built-in RegExp object's Replace method to perform this
Set re = New RegExp
' The pattern below means "one or more sequential space characters"
re.Pattern = "[ ]+"
re.Global = True
re.MultiLine = True
strCSVData = re.Replace(readline, ",")
On Error Resume Next
Set objFile = g_fso.OpenTextFile(strFilename, g_nMode, True)
nError = Err.Number
strErr = Err.Description
On Error Goto 0
If nError = 0 Then Exit Do
' Display a message indicating there were problems opening
' the file.
nResponse = crt.Dialog.MessageBox( _
"Failed to open """ & strFilename & """ (" & nError & "): " & _
vbcrlf & vbtab & strErr & vbcrlf & vbcrlf & _
"Check to see if the file is already open in another " & _
"application and make sure you have permissions to " & _
vbcrlf & "edit the file and create new files within the " & _
"destination folder.", _
"Save Operation Failed", _
If nResponse <> vbRetry Then Exit Sub
objFile.Write strCSVData & vbcrlf
g_strMode = "Wrote"
If g_nMode = ForAppending Then g_strMode = "Appended"
g_strMode & " " & Len(readline) & " bytes to file:" & vbcrlf & _
vbcrlf & strFilename
' Now open the CSV file in the default .csv file application handler...
'g_shell.Run chr(34) & strFilename & chr(34)
' Determine if we're running on Windows XP or not...
Set objWMIService = GetObject("winmgmts:" & _
Set colSettings = _
objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem")
For Each objOS In colSettings
' Windows XP "Name" might look like this:
' "Microsoft Windows XP Professional|C:\WINDOWS|\Device\Harddisk0\"...
' Vista might appear as follows:
' "Microsoft® Windows Vista™ Business |C:\Windows|\Device\Harddisk0\"...
strOsName = Split(objOS.Name, "|")(0)
If Instr(strOsName, "XP") > 0 Then
' Based on information obtained from
' NOTE: Will only work with Windows XP or newer since other OS's
' don't have a UserAccounts.CommonDialog ActiveX
' object registered.
Set objDialog = CreateObject("UserAccounts.CommonDialog")
objDialog.FileName = strDefault
objDialog.Filter = "CSV Files|*.csv|Text Files|*.txt|All Files|*.*"
objDialog.FilterIndex = 1
objDialog.InitialDir = g_shell.SpecialFolders("MyDocuments")
nResult = objDialog.ShowOpen
If nResult <> 0 Then
BrowseForFile = objDialog.FileName
' On Windows other than XP, we'll just pop up an InputBox
BrowseForFile = crt.Dialog.Prompt(_
"Save selected text to file:", _
"SecureCRT - Save Selected Text To File", _
Fortunately, since you want to capture the exact same rows/columns, if there is a certain prompt that is displayed when you access the second page, you can likely just insert a WaitForString, then call the SaveSelectedTextToCSVFile() function again.
SaveSelectedTextToCSVFile crt.Screen.WaitForString "#" SaveSelectedTextToCSVFile
Are you manually just executing the script via the Script menu when the first screen (where you wish to capture data) is displayed?
Yes, from the first page with the data, The amount of data will vary, Sometimes 2 pages other times 5 pages. But do not want to bite off too much scripting at one time. My idea is this.
1) work out getting the data off multiple pages
2) look for the last line of data that will start with the word "Total"
3) Get the script to run by itself every five minutes.
Eventually I will get there. But would just be glad to get the data at this point. Will try your comment tonight
If the data is variable, the prior idea will probably not work. The best way we can assist in your scripting efforts is to know what data the remote sends. This would be captured in a raw log.
To be clear on what you need to do to resolve this issue, as well as to help you with the future endeavors, can you collect a raw log of a "typical session" per the instructions below?
To create a raw log:
Since a raw log can contain sensitive information, feel free to send it as an attachment via e-mail to email@example.com. Please reference "Attn Brenda - Forum Thread #10259" in the subject line.
|Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)|
|Display Modes||Rate This Thread|