View Single Post
  #1  
Old 10-01-2014, 01:54 AM
redespace redespace is offline
Registered User
 
Join Date: Oct 2014
Posts: 12
Question Create separate log file for every hostname

Hi All,

I would like to have a separate log file for every hostname I connect to. I know that in the logging options there is a %H variable, but in my case it is not helpful.

The reason is that I have a Linux server I connect to, and I telnet/ssh from there to different hosts. I may sometimes even do a third jump from a secondary device. What I would like to do is to read the hostname from the screen (everything previous to "#" or ">") and use the hostname as the log file name.

Currently I have a script running that changes the tabname based on the hostname. I would like to add the log file part to it:


Code:
Sub Main()
DIM ScreenString
DIM StartPos
DIM Waiting
'DIM strprofiledir
'---- Get profile dir from windows ----
'Set wshShell = CreateObject( "WScript.Shell" )
'strprofiledir = wshShell.ExpandEnvironmentStrings( "%USERPROFILE%" )
'---- Get profile dir from windows ----
Do
ScreenString = crt.Screen.WaitForStrings ("#", "bash-3.2$", "netcss001{", "}:", ">")
If ScreenString = 1 then
Set objTab = crt.GetScriptTab()
nRow = objTab.Screen.CurrentRow
hostname = objTab.screen.Get(nRow, 0, nRow, objTab.Screen.CurrentColumn - 2)
hostname = Trim(hostname)
crt.window.caption = hostname
'logfile = (strprofiledir & "\SecureCRT Logs\" & hostname & ".txt")
'crt.Session.LogFileName = hostname
End If
If ScreenString = 2 then
crt.window.caption = "NETCSL001"
End If
If ScreenString = 3 then
crt.window.caption = "NETCSS001"
End If
If ScreenString = 4 then
crt.window.caption = "NETCSS001"
End If
If ScreenString = 5 then
Set objTab = crt.GetScriptTab()
nRow = objTab.Screen.CurrentRow
MyString = objTab.screen.Get(nRow, 0, nRow, objTab.Screen.CurrentColumn)
nColumn = InStr(MyString, "@")
hostname = objTab.screen.Get(nRow, nColumn + 1, nRow, objTab.Screen.CurrentColumn - 2)
hostname = Trim(hostname)
crt.window.caption = hostname
Waiting = crt.Screen.WaitForStrings( "quit", "exit", "sername", "ogin", "q")
End If
Loop
End Sub
I tried something, but it is not working. I commented out those parts.
Please help .
Thank you
Reply With Quote