#1
|
|||
|
|||
Logging on each tab
I'm trying to create a VBS script to perform the following,
1) connect to multiple hosts within tabs 2) log (raw) each tab with the "TabName__%Y%M%D%h%m%s.txt" 3) go to each tab and send a certain text string. I'm able to create the connections and name the tab as the host, at this point a box to name the log file opens for each connection. Once each connection has a file name then the text is sent. What is the trick to automatically name the files? Here is the script, # $language = "VBScript" # $interface = "1.0" '=============================================== 'LANG :VBScript 'VERSION : 1 '=============================================== Dim FSO, Shell, Windir, Runservice, File, File1 Dim g_objTab, g_strSkippedTabs, objProdTab, objTestTab, objDevTabm, objCurrentTab, nIndex Const ForReading = 1 Const ForWriting = 2 Const ForAppending = 8 Set FSO = CreateObject("scripting.filesystemobject") Set Shell = CreateObject("WScript.Shell") Set DeviceIP = FSO.opentextfile("c:\ftp\Rush\PORTS.txt", ForReading, False) Set Device1IP = FSO.opentextfile("c:\ftp\Rush\PORTS1.txt", ForReading, False) Set objDictionary = CreateObject("Scripting.Dictionary") Set objSc = crt.Screen Set objD = crt.Dialog Set objSe = crt.Session Set objW = crt.Window Logfiles = ("c:\ftp\Rush") While Not DeviceIP.atEndOfStream PORTS = DeviceIP.Readline() ' connect To host On port 23 (the Default telnet port) On Error Resume Next Set objProdTab = crt.Session.ConnectInTab("/telnet 10.255.0.94 "&PORTS&"") objProdTab.Screen.Synchronous = True objProdTab.Screen.WaitForString "]$", 1 objProdTab.Caption = ""&PORTS&"" wend Sub Main() Set g_objTab = crt.GetScriptTab g_objTab.Screen.Synchronous = True Dim nTest For nTest = 1 to crt.GetTabCount Set objCurrentTab = crt.GetTab(nTest) objCurrentTab.Activate if objCurrentTab.Session.Connected = True Then objCurrentTab.Session.Log True,False,True objCurrentTab.Session.LogFileName = "c:\1ftp\rush\"&PORTS&"_%Y%M%D%h%m%s%t.txt" end if next Dim nIndex2 For nIndex2 = 1 to crt.GetTabCount Set objCurrentTab = crt.GetTab(nIndex2) objCurrentTab.Activate objCurrentTab.Screen.Send chr(13) objCurrentTab.Screen.WaitForString "#",5 objCurrentTab.Screen.Send "thequickbrownfoxjumpsoverthelazydog123456789!@#$%^&*()_+" & vbcr objCurrentTab.Screen.WaitForString "#",5 next end sub Thanks, Don |
#2
|
||||
|
||||
Hello,
Before reviewing and testing your code to see if I can spot the issue, I'd like to mention the SecureCRT scripting manual. Section 7.1, Logging with SecureCRT's Session Object, seems like a good place to start. I see that the code you posted enables logging before the log file name is set. Code:
objCurrentTab.Session.Log True,False,True objCurrentTab.Session.LogFileName = "c:\1ftp\rush\"&PORTS&"_%Y%M%D%h%m%s%t.txt" The SecureCRT scripting manual (p. 85) shows disabling logging before setting the log file name. Start logging after the filename is changed. Code:
If crt.Session.Logging Then ' Turn off logging before setting up our script's ' logging... crt.Session.Log False End If ' Set up the log file so that it resides in the path ' defined in the TEMP environment variable, and is ' named according to the remote IP address: crt.Session.LogFileName = "%TEMP%\" & _ "LogFileForIP(" & crt.Session.RemoteAddress & ").txt" crt.Session.LogUsingSessionOptions ' Send commands, etc. ' ...
__________________
Mike VanDyke Software Technical Support [http://www.vandyke.com/support] |
#3
|
|||
|
|||
Mike,
Good catch on the logging enable in the wrong place. I've been playing with this script for a couple of days and have made numerous changes during that time, this being one of them. As far as the manual I've looked through it a few times looking for a solution with no luck. Thanks, Don |
#4
|
||||
|
||||
From pages 85-86 of the SecureCRT Scripting Manual, here is the code I thought would be the solution you needed, at least as far as logging is concerned.
Code:
If crt.Session.Logging Then ' Turn off logging before setting up our script's ' logging... crt.Session.Log False End If ' Set up the log file so that it resides in the path ' defined in the TEMP environment variable, and is ' named according to the remote IP address: crt.Session.LogFileName = "%TEMP%\" & _ "LogFileForIP(" & crt.Session.RemoteAddress & ").txt" crt.Session.LogUsingSessionOptions ' Send commands, etc. ' ... ' Stop logging crt.Session.Log False ' Perform other script work, or setup on the remote for the ' next batch of logging... ' ... ' Start logging again (be sure to append or else we'll ' overwrite the data we've logged so far). crt.Session.Log True, True ' Send more commands, etc. ' ... ' ...
__________________
Mike VanDyke Software Technical Support [http://www.vandyke.com/support] Last edited by miked; 10-09-2012 at 01:11 PM. Reason: incomplete post. |
#5
|
|||
|
|||
Micheal,
That looks like a solution for a single connection. I'm struggling with the logging for each tab. I need to open a raw log for each tab and leave them open until all commands are sent. Thanks, Don |
#6
|
||||
|
||||
Sorry about that oversight. The idea is the same - just replace crt.Session with objCurrentTab.Session.
I think the code which sets the log file name and starts logging should be called in your loop. Code:
Dim nTest For nTest = 1 to crt.GetTabCount Set objCurrentTab = crt.GetTab(nTest) objCurrentTab.Activate if objCurrentTab.Session.Connected = True Then ' This seems like a good place to enable logging EnableLoggingForTab(objCurrentTab) end if next
Quote:
Code:
Sub Main() Dim nTest For nTest = 1 To crt.GetTabCount Set objCurrentTab = crt.GetTab(nTest) objCurrentTab.Activate if objCurrentTab.Session.Connected = True Then ' This seems like a good place to enable logging EnableLoggingForTab(objCurrentTab) end if objCurrentTab.Screen.Send "ls" & vbcr Next End Sub Sub EnableLoggingForTab(ByRef ThisTab) If ThisTab.Session.Logging Then ' Turn off logging before setting up our script's ' logging... ThisTab.Session.Log False End If ' Set up the log file so that it resides in the path ' defined in the TEMP environment variable, and is ' named according to the remote IP address: ThisTab.Session.LogFileName = "c:\Temp\" & PORTS & "_%Y%M%D%h%m%s%t.txt" ' Start logging again (be sure to append or else we'll ' overwrite the data we've logged so far). 'ThisTab.Session.Log True, True ThisTab.Session.LogUsingSessionOptions End Sub
__________________
Mike VanDyke Software Technical Support [http://www.vandyke.com/support] |
#7
|
||||
|
||||
A logging substitution variable for the port has been added to a pre-beta version of SecureCRT. This means that the following script line:
Code:
ThisTab.Session.LogFileName = "c:\Temp\" & PORTS & "_%Y%M%D%h%m%s%t.txt" Code:
ThisTab.Session.LogFileName = "c:\Temp\" & "%P_%Y%M%D%h%m%s%t.txt" Maureen |
![]() |
Thread Tools | |
Display Modes | Rate This Thread |
|
|