Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 08-09-2014, 06:45 PM
bigkid123 bigkid123 is offline
Registered User
 
Join Date: Sep 2012
Posts: 2
Script to run in Tabs

All,

I am fairly new to writing scripts and very limited to the knowledge needed to even know where to start. I have modified this one but not quite sure of how to get it to execute in tabs that are already connected to my servers. I am basically saving the screen data to a file but would like all of the sessions to log to the same file. I believe the script that I have below would accomplish this but not sure of the code to use to have it run per open tab. Any help would be appreciated.

I also have an issue of when it writes the SessionName into the .txt file it includes the folders with the Session name and not sure how to only show the Session name.

I have found this script to do a single / but not sure how to change it to multiple folders.

strSession = crt.Session.Path
If Instr(strSession, "\") Then
vSession = Split(strSession, "\")
strSession = vSession(1)
MsgBox strSession
Else
MsgBox strSession
End If

I also found the following code which I believe would accomplish the send commands to multiple tabs but not quite sure how to update the script below to combine everything that I am needing.

Any help/guidance would be appreciated.

# $language = "VBScript"
# $interface = "1.0"

' Example script showing how to send commands to multiple tabs

Option Explicit

Sub Main()

Dim tab, index, nTabCount

nTabCount = crt.GetTabCount()

for index = 1 to nTabCount
set tab = crt.GetTab(index)
tab.activate
tab.screen.send "ping 192.168.0.131" & vbcr
next

End Sub

The script below is what I use to pull the needed data from the screen.

# $language = "VBScript"
# $interface = "1.0"

' This script demonstrates how to capture line by line output
' from a command sent to a server. It then saves each line of output
' to a file. This script shows how the 'WaitForStrings' command can be
' use to wait for multiple possible outputs.

' Constants used by OpenTextFile()
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

Sub Main

crt.Screen.Synchronous = True

' Create an instance of the scripting filesystem runtime so we can
' manipulate files.
'
Dim fso, file
Dim strSessionName
Set fso = CreateObject("Scripting.FileSystemObject")

' Open a file for writing. The last True parameter causes the file
' to be created if it doesn't exist.
'
Set file = fso.OpenTextFile("c:\scrt.config\%S.txt", ForAppending, True)

' Stuff the data from the SecureCRT screen into a variable
' Using crt.Screen.Get2 instead of crt.Screen.Get allows us to capture
' \r and \n so that data appears in the file the same way it appears in
' the SecureCRT window.
szScreenData = crt.Screen.Get2(1, 1, crt.screen.Rows, crt.Screen.Columns)

'msgbox szScreenData

' Write the line out with an appended '\r\n'

' Extract data displayed on row 2, between columns 1 and 2
nProcesses = crt.Screen.Get(7,1,7,41)

' Extract data displayed on row 5, between columns 36 and 41
nFreeMem = crt.Screen.Get(5,36,5,41)

strSessionName = crt.Session.Path

file.Write strSessionName & vbCrLf
file.Write nProcesses & vbCrLf
' file.Write “Free Memory: “ & nFreeMem & VbCrLf
' file.Write szScreenData & vbCrLf
file.Close

crt.screen.synchronous = false

End Sub
Reply With Quote
  #2  
Old 08-11-2014, 10:10 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
Hello bigkid123,

It's a little difficult to tell what your inquiries actually are.

Let me address this last problem first.

Quote:
I also have an issue of when it writes the SessionName into the .txt file it includes the folders with the Session name and not sure how to only show the Session name.
Are you referring to these lines of the script?

Code:
Set file = fso.OpenTextFile("c:\scrt.config\%S.txt", ForAppending, True)

...

file.Write strSessionName & vbCrLf

If so, the session name is being set to the full path per this line:

Code:
strSessionName = crt.Session.Path

Using the GetOption method available to the SessionConfiguration object is probably a better way to get just the session name.

SecureCRT's help file topic Scripting / Script Objects Reference contains explanations (and often examples) of all the object, methods and properties available in SecureCRT.

Another good resource (for just VBScript and SecureCRT in general) is the scripting manual (which may be where you already got the information on Get).


Quote:
I have modified this one but not quite sure of how to get it to execute in tabs that are already connected to my servers.
I am not quite sure what "this one" is. What was your starting point? One of our example scripts?

To iterate over sessions already opened in tabs, see the GetTabCount() method available to the Application object. You will probably need several of those other methods as well (GetActiveTab(), GetScriptTab(), etc.)
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 03-15-2015, 02:18 PM
bigkid123 bigkid123 is offline
Registered User
 
Join Date: Sep 2012
Posts: 2
Hi,

I just wanted to post a follow-up to this post as I was able to find a script on here and modify to my needs. This script will take data displayed between one column to another column and output the data to a text file for all opened tabs.

I have the data within the text file with the Tab Name and the data requested. Not sure if this will help others looking for something similar but thought I would post the resulting script.

Code:
# $language = "VBScript"
# $interface = "1.0"

' Example script showing how to send commands to multiple tabs
Option Explicit

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

Sub Main()

Dim objCurrentTab, nIndex, nTabCount, fso, file, strSessionName, szScreenData, nProcesses, nFreeMem, vSession, bConnected, nRows, nCols

Set fso = CreateObject("Scripting.FileSystemObject")

For nIndex = 1 To crt.GetTabCount
	Set objCurrentTab = crt.GetTab(nIndex)
		bConnected = objCurrentTab.Session.Connected
		if bConnected then
				nRows = objCurrentTab.Screen.Rows
        nCols = objCurrentTab.Screen.Columns

strSessionName = objCurrentTab.Session.Path

If Instr(strSessionName, "\") Then
vSession = Split(strSessionName, "Ahold\Ahold\")
strSessionName = vSession(1)
End If

' Extract data displayed on row 2, between columns 1 and 2 
nProcesses = objCurrentTab.Screen.Get(13,12,13,59) 

' Extract data displayed on row 5, between columns 36 and 41 
'nFreeMem = objCurrentTab.Screen.Get(5,36,5,41) 

Set file = fso.OpenTextFile("c:\scrt.config\ControllerReport.txt", ForAppending, True)
file.Write strSessionName & chr(9) & chr(9)
file.Write nProcesses & vbCrLf
file.Close
	End If
	
next

End Sub
Reply With Quote
Reply

Tags
run , script , sessionname , tabs

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:34 PM.