#1
|
|||
|
|||
change logging for all open Tabs
I would like to run a script so that it will create new log files with name according to prompt for all the open tabs. Following is my incomplete script. There are three variation in prompt. Prompt can be either “>” or “#” if prompt has bracket ‘(‘, ignore the text after open bracket. all tab has unique hostnames in this scenario.
Example: hostname> = hostname_new.txt hostname# = hostname_new.txt hostname(abcd)# = hostname_new.txt Code:
# $language = "VBScript" # $interface = "1.0" Option Explicit Const ForReading = 1 Const ForWriting = 2 Sub Main Dim str, tab, index, nTabCount nTabCount = crt.GetTabCount() for index = 1 to nTabCount set tab = crt.GetTab(index) tab.activate crt.Screen.Send Chr(13) crt.Screen.Send Chr(13) crt.Screen.Synchronous = True crt.Screen.WaitForString ">" ' hostname> crt.Screen.WaitForString "#" or "(" ' hostname# or hostname(xyz)# crt.session.logfilename="c:\Logs\" + "hostname_new.log" crt.session.log TRUE Loop next End Sub |
#2
|
|||
|
|||
Hi g114112118s,
To *capture data*, which it seems you need to do, you probably want to use ReadString(): Code:
strResult = crt.Screen.ReadString(">", "#", "(", 5)
__________________
Thanks, --Brenda VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#3
|
|||
|
|||
i am trying with following code but problem is that log file is not creating according to all open tab..anyone can share some thought...my idea is just create a log file based on the ongoing sessions prompt...
Code:
# $language = "VBScript" # $interface = "1.0" Sub Main Dim tab, index, nTabCount Dim objTab set objTab = crt.GetScriptTab nTabCount = crt.GetTabCount() for index = 1 to nTabCount set tab = crt.GetTab(index) tab.activate crt.Screen.Send Chr(13) crt.Screen.Send Chr(13) strPrompt = Replace(strPrompt,"(","") strPrompt = Replace(strPrompt,">","") strPrompt = Replace(strPrompt,"#","") objTab.Caption = strPrompt strPrompt = GetPrompt() crt.Screen.Synchronous = True crt.Screen.Send Chr(13) crt.session.log = False crt.session.logfilename= "h:\config\Desktop\CRT\Logs\" & strPrompt & "_new.log" crt.session.log = True crt.Screen.Send Chr(13) crt.screen.WaitForString ">" crt.Screen.Synchronous = False next End Sub '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Function GetPrompt() Do crt.screen.send vbcr Do bCursorMoved = crt.Screen.WaitForCursor(1) Loop Until bCursorMoved = False strPrompt = Trim(strPrompt) If strPrompt <> "" Then Exit Do Loop GetPrompt = strPrompt End Function |
#4
|
|||
|
|||
Hi g114112118s,
Quote:
What problem are you trying to solve? On the eighth line inside the For loop, you have set the caption to be the current prompt with replacements: Code:
strPrompt = Replace(strPrompt,"(","") strPrompt = Replace(strPrompt,">","") strPrompt = Replace(strPrompt,"#","") objTab.Caption = strPrompt Code:
strPrompt = GetPrompt() Code:
crt.Dialog.MessageBox strPrompt crt.session.logfilename= "h:\config\Desktop\CRT\Logs\" & strPrompt & "_new.log" Are there any characters that the OS does not permit to be used in filenames?
__________________
Thanks, --Brenda VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#5
|
|||
|
|||
Hi, Brenda,
>Does this reflect the name you would like used in naming log files? Yes, i need to deal with lots of hosts/tabs at a time. And sometime i need separate logs. So instead of changing log files from file menu manually. i wanted to automate this task so fresh log file will be created upon the execution of script as prompt_xyz.txt What overall i am trying to do is: 1) Counting TAB via nTabCount = crt.GetTabCount() 2) Go though the each tab for index = 1 to nTabCount 3) Turnoff logging 4) Get prompt 5) Enable logging 6) New logging file name should be promptA_xyz.txt for 2nd tab log filename should be promptB_xyz.txt and so on >Why not put in a message box just before the specifying logfilename I tried this option but only posted clean code for readability purpose. Current problem is that value of strPrompt is not changing. It’s get the correct prompt for the intial tab from where script is executed but later strPrompt value doesn’t change. Code:
# $language = "VBScript" # $interface = "1.0" Sub Main Dim tab, index, nTabCount Dim objTab set objTab = crt.GetScriptTab nTabCount = crt.GetTabCount() msgbox "Tab = " & nTabCount for index = 1 to nTabCount msgbox "index = " & index set tab = crt.GetTab(index) tab.activate crt.Screen.Send Chr(13) crt.Screen.Send Chr(13) strPrompt = Replace(strPrompt,"(","") strPrompt = Replace(strPrompt,">","") strPrompt = Replace(strPrompt,"#","") objTab.Caption = strPrompt strPrompt = GetPrompt() crt.Screen.Synchronous = True crt.Screen.Send Chr(13) crt.session.log False crt.Dialog.MessageBox "strPrompt = " & strPrompt crt.session.logfilename= "h:\config\Desktop\CRT\Logs\" & strPrompt & ".log" crt.session.log True crt.Screen.Send Chr(13) crt.Screen.Synchronous = False next End Sub '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Function GetPrompt() Do crt.screen.send vbcr Do bCursorMoved = crt.Screen.WaitForCursor(1) Loop Until bCursorMoved = False nRow = crt.Screen.CurrentRow strPrompt = crt.screen.Get(nRow, _ 0, _ nRow, _ crt.Screen.CurrentColumn - 1) strPrompt = Trim(strPrompt) If strPrompt <> "" Then Exit Do Loop GetPrompt = strPrompt End Function |
#6
|
|||
|
|||
Hi g114112118s,
Below is some example code for accomplishing your objective. If you map the script to a button on the button bar and then hold the Shift key when you click that button, the script will execute in all connected (unlocked) tabs: Changes in SecureCRT 7.1 (Beta 1) -- February 26, 2013 (7.1.0.195) ------------------------------------------------------ New features:
Code:
Sub Main() ' Turn on Synchronous screen interaction crt.Screen.Synchronous = True ' Simulate pressing the <enter> key: crt.Screen.Send chr(13) ' Wait for the CR/LF to appear from that line crt.Screen.WaitForString vbcrlf ' Now read everything received until we see either a #, >, or ( strHostname = crt.Screen.ReadString("#", ">", "(") ' Turn off logging if it's on already: crt.Session.Log False ' Now set up the log file name, use SecureCRT's template parameters ' to automatically time-stamp the log file strLogFilename = "C:\Logs\" & strHostname & "_%Y%M%D-%h%m%s.%t_log.txt" crt.Session.LogFilename = strLogFilename ' Now, start logging. crt.Session.Log True ' Now that we're logging, we can get a reference to the log file name ' that is in use: strActualLogFileName = crt.Session.LogFilename ' Display it in the status bar: crt.Session.SetStatusText "Log: " & strActualLogFileName End Sub
__________________
Thanks, --Brenda VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#7
|
|||
|
|||
Hi, Brenda,
That's the gr8 help. Much appreciated. But since i am using 6.7.3 I don't have features SHIFT+<click>. Tried following but some tab creates new log sessions but some won't. Code:
# $language = "VBScript" # $interface = "1.0" Sub Main Dim nTabIndex For nTabIndex = 1 To crt.GetTabCount Set objTab = crt.GetTab(nTabIndex) objTab.Activate objTab.Screen.Synchronous = True If objTab.Session.Connected Then {code} End If next End Sub |
#8
|
|||
|
|||
__________________
Thanks, --Brenda VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#9
|
|||
|
|||
Hi, Brenda,
Thank you but PC has restriction and unable to run installers. If it is possible please help to correct the script. As general suggestion, it’s good to have portable version also available on download page. |
#10
|
|||
|
|||
Hi g114112118s,
I have added this thread to a feature request in our product enhancement database for a version to run in PortableApps environment (USB stick). Should a future release of SecureCRT include this feature, notification will be posted here. If you prefer direct email notification, send an email to support@vandyke.com and include "Feature Request - Forum Thread #12744" in the subject line or use this form from the support page of our website. Please clarify what sticking points you still have with your script: Quote:
Please also post the complete script (with sensitive data redacted).
__________________
Thanks, --Brenda VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#11
|
|||
|
|||
Hi g114112118s,
Before we continue, please send a screenshot of the Help / About SecureCRT... dialog to support@vandyke.com and reference "Attn Brenda - Forum Thread #12744" in the subject line.
__________________
Thanks, --Brenda VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
![]() |
Thread Tools | |
Display Modes | Rate This Thread |
|
|