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 07-09-2017, 07:46 PM
g114112118s g114112118s is offline
Registered User
 
Join Date: Aug 2010
Posts: 24
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
Reply With Quote
  #2  
Old 07-10-2017, 09:34 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
Hi g114112118s,

To *capture data*, which it seems you need to do, you probably want to use ReadString():

Code:
	strResult = crt.Screen.ReadString(">", "#", "(", 5)
You can read about capturing data in Chapter 4 of the scripting manual here.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 07-23-2017, 07:25 PM
g114112118s g114112118s is offline
Registered User
 
Join Date: Aug 2010
Posts: 24
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
Reply With Quote
  #4  
Old 07-24-2017, 08:19 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
Hi g114112118s,

Quote:
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...
What results are you getting?

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
But then you get the prompt again on the ninth line:

Code:
        strPrompt = GetPrompt()
Why not put in a message box just before the specifying logfilename?

Code:
    crt.Dialog.MessageBox strPrompt
    crt.session.logfilename= "h:\config\Desktop\CRT\Logs\" & strPrompt & "_new.log"
Does this reflect the name you would like used in naming log files?

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
Reply With Quote
  #5  
Old 07-24-2017, 10:46 PM
g114112118s g114112118s is offline
Registered User
 
Join Date: Aug 2010
Posts: 24
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
Reply With Quote
  #6  
Old 07-25-2017, 09:15 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
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:

  • A button action can be sent to all connected tabbed or tiled sessions by pressing SHIFT+<click> on the button.


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
Reply With Quote
  #7  
Old 07-25-2017, 08:30 PM
g114112118s g114112118s is offline
Registered User
 
Join Date: Aug 2010
Posts: 24
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
Reply With Quote
  #8  
Old 07-26-2017, 08:25 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
Hi g114112118s,

You might check your upgrade eligibility here.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #9  
Old 07-27-2017, 04:32 AM
g114112118s g114112118s is offline
Registered User
 
Join Date: Aug 2010
Posts: 24
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.
Reply With Quote
  #10  
Old 07-27-2017, 11:10 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
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:
Tried following but some tab creates new log sessions but some won't.
Please elaborate (as you did in the other thread) as to what the test scenario is, along with the explicit results.

Please also post the complete script (with sensitive data redacted).
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #11  
Old 07-27-2017, 11:44 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
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
Reply With Quote
Reply

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 12:07 AM.