Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 01-04-2018, 02:21 AM
Etoneja Etoneja is offline
Registered User
 
Join Date: Jan 2018
Posts: 3
Execure logon script before session connected

Hello!

I have a task: I want to log every connect try through SecureCRT, even if connect not successful. Its a easy task, if I connect to remote host, but I have some difficulties with another cases.

For example simple script:
Code:
#$language = "VBScript"
#$interface = "1.0"

MsgBox "test"
(Ofc, in real script I execute something else).
So, it works fine with normal (successful) connection, but if host is down or wrong script doesn't even start.

Yes, I can check connection status, if I run script from another tab, and not by quickconnect or by handle a telnet-link.

Is there a way to start script in this case (host don't answer or hostname wrong)?
Reply With Quote
  #2  
Old 01-04-2018, 09:11 AM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
Hi Etoneja,

I'm sorry you're having trouble.

How are you launching your script? If for example you are using Logon Actions this will only start a script after successfully authenticating.

There may some options that you can use to get the behavior you want. The first would be to attempt the connections from inside a script, use the script to make the connections.

The second would be to configure automatic logging in SecureCRT. I've attached a pdf that helps demonstrate setting up logging in SecureCRT. If you are using ad-hoc connections, such as Quick Connect, you may need to make some modification to the formatting of the variables. In order to use logging with ad-hoc connections you will also need to make the changes to your Default Session.

Do either of these options sound like they would work for you?
Attached Files
File Type: pdf SCRT_Logging_Template.pdf (59.0 KB, 341 views)
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 01-05-2018, 02:58 AM
Etoneja Etoneja is offline
Registered User
 
Join Date: Jan 2018
Posts: 3
Thannk for fast and quality feedback.

Quote:
Originally Posted by ekoranyi View Post
How are you launching your script? If for example you are using Logon Actions this will only start a script after successfully authenticating.
That is the answer I wanted to hear.
Yes, I'm launching my script through Logon Actions.

I know about automatic logging in CRT, It's not the something I truly need.

Now my difficulty consist in the conflict between the two scripts (script, that creates a new session, and logon script).

I try to describe it with additional information:
1) My main script creates a new connection (get var IPaddress through input, correct it, add some options, create a connectintab). Example:
Code:
Set Tab = crt.session.ConnectInTab ("/telnet " &  IPaddress & " 23")
and trying to get some information about it:
Code:
if tab.Session.Connected = -1 Then
	crt.screen.send "Connected"
End If
If tab.Session.Connected = 0 Then
	crt.screen.send "Disconnected"
End if
In basic variant I want only to wait Connected or Disconnected. If Connected then stops, If disconnected then analyze possible reasons of it.

2) My Logon Script works pretty simple: wait and send. Number of different variations of login and password not equal to 1 and depends of area/vendor/device moden/etc and script tries to guess it.
3) I use Logon script separate from main script for the reason, that I also create a connections through handling telnet-links, and not only by main script.
4) Problem 1: my main script works well if I disable logon script. And don't work, it I enable logon script. I don't get, How to make them both works at the same time.

Something close to task I found in threads. Something close, but not the same as I want and need.
https://forums.vandyke.com/archive/i...hp/t-7034.html
https://forums.vandyke.com/showthread.php?t=1040
Reply With Quote
  #4  
Old 01-05-2018, 12:59 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,635
Hi Etoneja,

We think the best way you could probably accomplish your objective is to make a new session you use as the template for when you want to run the Main Script. Make its protocol Telnet and any other configuration needed and that's what you would use instead of Default Session since it will be configured with the Logon Script.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #5  
Old 01-05-2018, 02:37 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,635
Hi Etoneja,

So I have included some example code below from our script guru that illustrates how you could leverage this "main template" for connecting new sessions.

You would either need to incorporate the authentication from your existing logon script or perhaps you could use Include as illustrated in the "Sharing Script Code" section of the script examples on our website here. I'm referring specifically to CallModule.vbs and Module.vbs.

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

Sub Main()
    If crt.Arguments.Count > 0 Then
        strHost = crt.Arguments(0)
    Else
        strHost = "192.168.0.1"
    End If

    If crt.Arguments.Count > 1 Then
        nPort = CLNG(crt.Arguments(1))
    Else
        nPort = 23
    End If

    Set objConfig = LoadSessionConfig("__MainTemplate__")
    objConfig.SetOption "Protocol Name", "Telnet"
    objConfig.SetOption "Hostname", strHost
    objConfig.SetOption "Port", nPort
    objConfig.SetOption "Trace Level", 1
    objConfig.SetOption "Title Bar", strHost
    objConfig.SetOption "Use Title Bar", True
    objConfig.SetOption "Use Script File", False

    On Error Resume Next
    Set Tab = objConfig.ConnectInTab
    strErr = Err.Description
    nError = Err.Number
    On Error Goto 0

    If nError <> 0 Then
        bConnected = False
    Else
        If Tab.Session.Connected Then
            bConnected = True
        Else
            bConnected = False
        End If
    End If

    If bConnected Then
        crt.Session.SetStatusText "Connected"
    Else
        crt.Session.SetStatusText "Disconnected"
    End If
End Sub


'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function LoadSessionConfig(strSessionName)
    ' Attempt to open the existing session configuration specified
    ' by the caller in strSessionName
    On Error Resume Next
    Set objConfig = crt.OpenSessionConfiguration(strSessionName)
    nError = Err.Number
    strErr = Err.Description
    On Error Goto 0

    ' If SecureCRT failed to open the session, create a new one based
    ' on the Default session:
    If nError <> 0 Then
        Set objConfig = crt.OpenSessionConfiguration("Default")
        objConfig.Save strSessionName
    End If

    ' Return the session (existing or new, depending on the situation)
    ' to the caller:
    Set LoadSessionConfig = objConfig
End Function
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #6  
Old 01-09-2018, 03:01 PM
Etoneja Etoneja is offline
Registered User
 
Join Date: Jan 2018
Posts: 3
Quote:
Originally Posted by bgagnon View Post
Hi Etoneja,

We think the best way you could probably accomplish your objective is to make a new session you use as the template for when you want to run the Main Script.
Thank you for the detailed answer with an example.

You offered an amusing solution. It sounds and looks like something that should solve my task.

I'm going to check this principle in the near future.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 02:15 PM.