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 06-04-2019, 02:03 AM
ecox ecox is offline
Registered User
 
Join Date: Jan 2019
Posts: 38
Question Questions regarding "Read Data From Separate Hosts/Commands"

Hi folks,

as mentioned in the subject, I have a question about this script "Example: Read Data From Separate Hosts/Commands File And Log To Individual Files"

Quote:
Allow host to be specified as either existing sessions in the
session manager (in which case the existing session is used to
establish the connection), or a hostname/IP which which an ad
hoc connection is made. To force SecureCRT to make an ad hoc
connection even if an existing session is found to match the
host entry specified, set g_bUseExistingSessions = False below.
If a host matches an existing session, and the session has
a saved username and password (or Automate Logon option is
enabled, the script will not send any credentials in the Connect()
function defined below. Instead, it is expected that the session
will authenticate itself using credentials stored within the session.
I do not understand that, my problem is:
SecureCRT opens a new session for each device. Why does not he execute the commands on the session I'm on? It's important that he does that from the session I've chosen.

How can i handle this?

1) Connect to the devices (hosts.txt)
2) set up commands then exit and go to the next device in host-list
3) log this to a single-file....

Greets
ecox
Reply With Quote
  #2  
Old 06-04-2019, 10:16 AM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 914
Quote:
Originally Posted by ecox View Post
my problem is:
SecureCRT opens a new session for each device.
Yes. Opening a new session for each device is exactly this example script is designed to do. The script tells SecureCRT to establish a connection (from the machine on which SecureCRT is actually installed and running) to the specified host -- whether that host be:
  • a saved session
    or
  • an ad hoc connection, e.g. using a saved session in SecureCRT using a connect method similar to what Quick Connect does to establish a connection.

Quote:
Originally Posted by ecox View Post
Why does not he execute the commands on the session I'm on?
It seems like what you want to do is:
  • Use an already-connected session to a remote host (say, is it a "gateway" or "jump host" you're connected to?), then
  • Tell that host to connect to another host (like, run an 'ssh host1' or 'telnet host1' command to get to another host),
  • Once connected to the secondary host from there, run commands on that secondary host, and then
  • "exit" that connection between the primary host and the secondary host and then...
  • Move on to the next secondary host.
Does this list accurately reflect what you want to do?

If not, would you be so kind as to provide more explicit details related to your objective, giving concrete examples?

If it does reflect what you want to accomplish, we simply don't have a complete example for you.

There are bits and pieces, however, which you could put together and use to roll your own solution using this script as your base starting point...
One approach would be:
  1. Modify the base script's Connect() function (it's defined within the script file itself) to run your 'ssh' or 'telnet' command to get to the specified host instead of calling crt.Session.ConnectInTab()
  2. Hint: Use the approach exemplified in this other example script, "Example: Jump Host - Handle Secondary Host Connection Attempts" to handle the secondary host connection and authentication.
  3. Modify the part of the base script which currently tells the tab's Session object to Disconnect() to instead send "exit" & vbcr, and wait for your jump host's shell prompt to appear so that the script knows when it's appropriate to move on to the next host in you hosts file.
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #3  
Old 06-05-2019, 12:08 AM
ecox ecox is offline
Registered User
 
Join Date: Jan 2019
Posts: 38
Hey ho

Morning Jdev,

So my plan is:
-I am already connected to a Jumpserver
-From this Jumpserver, should happen to the following:

all in only one session
Code:
ssh -l admin 1.1.1.1
*automatic login
uptime
*disconnect or quit, exit
*write down the results in a *.txt-file or whatever
*then connect to the next-device (hosts.txt)
ssh -l admin 1.1.1.2
*automatic login
and so on....
...
...
How can I implement this?
Where can I select the "saved session" for this script?

Regards
ecox

Last edited by ecox; 06-05-2019 at 03:39 AM.
Reply With Quote
  #4  
Old 06-05-2019, 10:10 AM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 914
Quote:
Originally Posted by ecox View Post
So my plan is:
-I am already connected to a Jumpserver
-From this Jumpserver, should happen to the following:

all in only one session
Code:
ssh -l admin 1.1.1.1
*automatic login
uptime
*disconnect or quit, exit
*write down the results in a *.txt-file or whatever
*then connect to the next-device (hosts.txt)
ssh -l admin 1.1.1.2
*automatic login
and so on....
...
...
How can I implement this?
Where can I select the "saved session" for this script?

You wouldn't select any saved session to connect with; before running the script, you'd already be connected to your jump host, right?

I gave some clues on how you could implement it, generally, in my last message. Here's a review of what I wrote:

Quote:
Originally Posted by jdev View Post
There are bits and pieces, however, which you could put together and use to roll your own solution using this script as your base starting point...
One approach would be:
  1. Modify the base script's Connect() function (it's defined within the script file itself) to run your 'ssh' or 'telnet' command to get to the specified host instead of calling crt.Session.ConnectInTab()
  2. Hint: Use the approach exemplified in this other example script, "Example: Jump Host - Handle Secondary Host Connection Attempts" to handle the secondary host connection and authentication.
  3. Modify the part of the base script which currently tells the tab's Session object to Disconnect() to instead send "exit" & vbcr, and wait for your jump host's shell prompt to appear so that the script knows when it's appropriate to move on to the next host in you hosts file.
In other words, your entire Connect() function in the RunCommandsOnMultipleHostsAnLogResults script would be replaced. Instead, you'd structure it to 'connect' with your "ssh -l admin" command to the specified host (passed in as an argument to the function), driving the connection and authentication process as described/demonstrated in the aforementioned Example: Jump Host - Handle Secondary Host Connection Attempts.

What specific problem are you having with this suggested approach?

Where, specifically, are you stuck?

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #5  
Old 06-05-2019, 11:44 AM
ecox ecox is offline
Registered User
 
Join Date: Jan 2019
Posts: 38
Hi jdev,

thanks in advance for ur help ...and sorry for my english ^^

I found the function. This is with "connectInTab" probably not quite what I need, right.

I am stuck because I do not know what exactly I need from the script "Example: Jump Host - Handle Secondary Host Connection Attempts" and what I need to replace it with in "RunCommandsOnMultipleHostsAnLogResults".

That's all: D

My VB skills still leave something to be desired - I can read the code itself, but does not always know quite where the action goes, this is then a lot of try and error.

greetz
Reply With Quote
  #6  
Old 06-05-2019, 03:37 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 914
Quote:
Originally Posted by ecox View Post
My VB skills still leave something to be desired - I can read the code itself, but does not always know quite where the action goes, this is then a lot of try and error.
Trial and error is how good learning can happen.

There isn't a turn-key solution for you, so you'll have to experiment and learn from failures. You will have to learn some VBScript. We don't provide VBScript training, but there is a how-to guide you can use as a starting place. Read through it and become familiar with the concepts as you strive to create your own solution as it will help you to understand more VBScript code.

The JumpHost-HandleSecondaryHostConnectionAttempts.vbs.txt example script:
  1. Sets up an array of host ip addresses.
    Code:
    vHosts = Array(_
        "192.168.0.1",_
        "192.168.1.1",_
        "192.168.0.2")
    You would not need this array because your base script will be reading in hosts from a hosts.txt file.

  2. Sets up an array of possible shell "responses". This is done in preparation for handling the possibilities of text that might be seen in SecureCRT's screen when the "ssh" command is launched.
    Code:
    ' The order of elements in this array should be in the order of:
    '  - Expected login prompts (eg: "-->", "#", etc.)
    '  - Special cases (accept host key, enter pwd, enter username, etc.)
    '  - Fail/Bail cases (wrong pwd/login, hostname not found, time out, etc.)
    vPossibleResponses = Array(_
        "-->",_
        "$",_
        "ogin:", _
        "ame:", _
        "(yes/no)?",_
        "sword:",_
        "Permission denied",_
        "incorrect", _
        "not known", _
        "timed out")
    You will need this array. Copy the code into the Connect() method of the base script you're modifying (replace the contents of the existing Connect() function).

    Note that the first two elements of this vPossibleResponses array constitute two examples of shell prompts that would be seen *after* successfully ssh'ing to a secondary host. If your secondary host's shell prompt isn't --> or $, then you should modify the first one to match the portion of secondary host shell prompts that is common to all of your secondary hosts. If you have some secondary hosts that have one thing common that isn't present on other secondary hosts, change the second one ($) to match the type of shell prompt you'd expect to see on your secondary hosts.

  3. Defines a shell prompt string value (strJumpHostPrompt) as "-->". You'll need to set this to represent the shell prompt of your Jump host so that the script will know when the 'ssh' command has failed, etc. (and when the 'exit' has succeeded, if you got successfully connected to the secondary host).

  4. Enters a Do..Loop in which every host in the vHosts array is iterated over from first to last. You would be effectively transferring everying inside the Do..Loop (exclusively, meaning you don't copy over the Do and Loop lines themselves, but everything in between them) and put this into the Connect() function of the base script you're modifying -- place it underneath the vPossibleResponses array code you already put there.

    You will need to modify the command that is formulated: strCommand = "ssh user@ & vHosts(nIndex)". You have a different command (ssh -l admin host), so you'll have to edit the command, and use the host that will be passed in to your Connect function.

    Note that there are nested Do..Loop blocks in the Jump Host example: an inner loop and an outer loop (look at the comments in the code... the words "inner" and "outer" are used to help you out).

    You'll need the inner Do..Loop, but only part of the guts in the outer Do..Loop.

    With a little modification to accommodate some things that I would anticipate, your new Connect() method in the base script you're modifying might look something like this.
    Code:
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Function Connect(strHost)
        ' The order of elements in this array should be in the order of:
        '  - Expected login prompts (eg: "-->", "#", etc.)
        '  - Special cases (accept host key, enter pwd, enter username, etc.)
        '  - Fail/Bail cases (wrong pwd/login, hostname not found, time out, etc.)
        vPossibleResponses = Array(_
            "-->",_
            "$",_
            "ogin:", _
            "ame:", _
            "(yes/no)?",_
            "sword:",_
            "Permission denied",_
            "incorrect", _
            "not known", _
            "timed out")
    
        strJumpHostPrompt = "-->"
    
        ' Compose our command
        strCommand = "ssh -l admin " & strHost
        ' Now, send the command
        crt.Screen.Send strCommand & vbcr
    
        ' Wait for our command to be echoed back to us so we know that it has been
        ' received before we attempt to wait for all possible responses.
        crt.Screen.WaitForString strCommand & vbcr
    
        ' Start a Do..Loop that looks for all defined possible responses to
        ' the telnet... or ssh... command we just sent.
        Do
            crt.Screen.WaitForStrings vPossibleResponses
            If crt.Screen.MatchIndex > 0 Then
                strStringFound = vPossibleResponses(crt.Screen.MatchIndex - 1)
            End If
            Select Case crt.Screen.MatchIndex
                Case 1,2
                    ' Found "-->" or "$" which in our example indicate successful
                    ' authentications because these are secondary host prompt value
                    ' possibilities
    
                    ' Return True so that the caller will know we were successful.
                    Connect = True
                    Exit Function
    
                Case 3,4
                    ' Found "ogin" or "ame" which means waiting for user account.
                    crt.Screen.Send strUsername & vbcr
                    ' Wait for the username to appear echo'd from the remote so
                    ' that we know it's been received...
                    crt.Screen.WaitForString strUsername
    
                    ' Fall through to the top of the inner Do..Loop to continue
                    ' waiting for strings until all possibilities are exhausted.
    
                Case 5
                    ' Found new hostkey prompt.  This indicates that this is the
                    ' first time we have connected to the remote machine, and we
                    ' need to accept the hostkey.
                    crt.Screen.Send "yes" & vbcr
                    ' Wait for the "yes" to be echo'd back from the remote so
                    ' we know it has been received:
                    crt.Screen.WaitForString "yes"
    
                    ' Fall through to the top of the inner Do..Loop to continue
                    ' waiting for strings until all possibilities are exhausted.
    
                Case 6
                    ' We are being prompted for a password.  Send it.
                    crt.Screen.Send strPassword & vbcr
                    ' Passwords are not echo'd by the remote, so don't wait for
                    ' it to appear, instead...
                    ' Fall through to the top of the inner Do..Loop to continue
                    ' waiting for strings until all possibilities are exhausted.
    
                Case 7
                    ' SSH Password was denied or login was incorrect.  Exit this
                    ' inner Do..Loop and return False
    
                    ' First cancel the current ssh authentication attempt to the
                    ' secondary host.
                    crt.Screen.SendKeys "^c"
    
                    ' Wait for an indication that the Ctrl+C was successful before
                    ' attempting to connect to next host.
                    crt.Screen.WaitForString strJumpHostPrompt
    
                    ' Exit the function, returning False.
                    Connect = False
                    Exit Function
    
                Case 8
                    ' Telnet login or password was incorrect.  Exit this inner
                    ' Do..Loop and move on to the next host.
    
                    ' First cancel the current authentication attempt to the
                    ' secondary host.
                    crt.Screen.SendKeys "^]"
                    crt.Screen.WaitForString "telnet>"
                    crt.Screen.Send "quit" & vbcr
    
                    ' Wait for an indication that the Ctrl+C was successful before
                    ' attempting to connect to next host.
                    crt.Screen.WaitForString strJumpHostPrompt
    
                    Connect = False
                    Exit Function
    
                Case 9,10
                    ' Not able to reach secondary host.  Connection timed out.
                    ' Wait for primary host prompt before exiting inner Do..Loop.
                    crt.Screen.WaitForString strJumpHostPrompt
    
                    ' Exit function with a False
                    Connect = False
                    Exit Function
    
                Case Else
                    ' Let user know that there is an unhandled case
                    crt.Session.SetStatusText _
                        "Unhandled """ & strStringFound & """"
                    ' Yikes... Never expect to be here, but if we got here, it's
                    ' probably a programming error you've introduced with the
                    ' 'vPossibleResponses' variable that you'll need to fix
                    crt.Dialog.MessageBox "Yikes!" & vbcrlf & vbcrlf & _
                        "We never expect to get here. if you see this, you" & _
                        vbcrlf & _
                        "have probably introduced a programming error into" & _
                        vbcrlf & _
                        "your script code which will you will need to fix." & _
                        vbcrlf & vbcrlf & _
                        "Chances are you added a string to vPossibleResponses " & _
                        vbcrlf & _
                        "but you haven't added the code to handle " & _
                        vbcrlf & _
                        "what to do when that special string was found:" & _
                        vbcrlf & vbcrlf & vbtab & """" & strStringFound & """"
                    crt.Screen.SendSpecial "MENU_SCRIPT_CANCEL"
    
                End Select
        Loop ' Loop waiting for possible responses to the 'ssh' or 'telnet' command.
    
        ' If the code gets here, then we must have been unsuccessful in finding
        ' the secondary host shell prompt... we must return False here.
        Connect = False
    End Function


Take some time to digest what I've written, read the scripting guide, etc.

Once you've made some coding attempts and get stuck, post your code and the exact error you're seeing along with output from the terminal screen of SecureCRT and we'll see what can be done to help point you in the right next direction.

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #7  
Old 06-06-2019, 01:09 AM
ecox ecox is offline
Registered User
 
Join Date: Jan 2019
Posts: 38
Hi jdev,

I had to create the variable "strPassword" in the function. Otherwise he always sent an empty password (g_strPassword?). Ok, now he can send the command and log in to the device. When I arrive at the prompt (>), the script stops. If I type in exit and get back on the jumphost ($), the script will stop on line 353. The connection works but no command is issued from the commands.txt and nothing is written to a text file. I've read through your text several times, but come to no solution ... to despair..I just want it to work: D

Maybe you can support again.

What should still happen:
1) Connect to device
2) Set a command and write down to * .txt (single-file)
3) Disconnect from router
4) Connect to next device
5) Set a command (same as in step 2) and write down in * .txt
6) Disconnect from router
and so on ...

Actually easy, I think, but I have problems implementing it.

Script u can see @ https://github.com/ecox3108/readandl...ster/randl.vbs

Greetz
Reply With Quote
  #8  
Old 06-06-2019, 01:50 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 914
Quote:
Originally Posted by ecox View Post
Actually easy, I think, but I have problems implementing it.
Then it isn't really that easy, right?

Keep working through each problem you encounter one-by-one and you'll get a solution in place.

A picture is worth a few words here...



If you replace the "$" with ">" in the second slot of your vPossibleResponses array, does your script get any farther?

Hint: if your script is just sitting there appearing to do nothing, use Script > Cancel to reveal which line of code the script is on.

If it's a "WaitForString" call, ask yourself, "Why is WaitForString() still sitting there... what is on the screen that I don't have in the vPossibleResponses array?"

If you continue to have problems and request assistance, it will be much more helpful to see what's on the Screen in SecureCRT at the time your script seems to hang or otherwise fail to progress as you hope.

--Jake
Attached Images
File Type: png ecox-forum-script-prob-secd-prompts.png (153.3 KB, 33 views)
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #9  
Old 06-07-2019, 01:28 AM
ecox ecox is offline
Registered User
 
Join Date: Jan 2019
Posts: 38
Hi jdev,

i replace the "$" with ">" (see github for acutally code), login process works fine but same error i think...
acutally code:
https://github.com/ecox3108/readandl...ster/randl.vbs

i think, we got problems with the variables maybe :/. if i comment out the lines 328-342, the script run is still running with the same error @line 353, but i have to repleace "strHost" with "g_strHost" in line 681...
confusing
And the second host, is the host on which the command should be issued. i jump from bash$ via ssh to a router (hosts.txt), then the command should setup and log append to a txt-file
sorry dude, my english, i hope u understand whats my plan


ignore the first four lines (strg+c ^^)

greets
ecox
Attached Images
File Type: jpg SecureCRT.jpg (71.4 KB, 29 views)

Last edited by ecox; 06-07-2019 at 08:12 AM.
Reply With Quote
  #10  
Old 06-07-2019, 02:02 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 914
Quote:
Originally Posted by ecox View Post
i think, we got problems with the variables maybe :/. if i comment out the lines 328-342, the script run is still running with the same error @line 353, but i have to repleace "strHost" with "g_strHost" in line 681...confusing
The Connect() method has been customized to meet your specific needs, so what gets passed as as a parameter will need to be customized appropriately. Currently, your call to Connect() on line 346 is passing in the strConnectString as a parameter. Instead, it should be passing in g_strHost. For example:
Code:
' Call the Connect() function defined below in this script.  It handles 
' the connection process, returning success/fail. 
If Not Connect(g_strHost) Then
This will allow you to put things back to using strHost in your Connect() method -- or you can simply leave it as is and pass nothing into the new Connect() method and have it always use the g_strHost variable. Your choice.

Quote:
Originally Posted by ecox View Post
And the second host, is the host on which the command should be issued. i jump from bash$ via ssh to a router (hosts.txt), then the command should setup and log append to a txt-file


ignore the first four lines (strg+c ^^)
I don't know German, but I would bet that the error you're seeing now is that there is no such object named g_objNewTab.

This would be another side effect of customizing your Connect() method to meet your needs. The example/old Connect() method initiated the connection to the remote host directly within SecureCRT, setting the g_objNewTab variable to reflect the newly connected tab in which the connection to the specified host was established. In your case, however, you're wanting to use the already connected tab and drive the jump host's ssh program to get you connected to a secondary host, execute commands, and so on... so the g_objNewTab object doesn't have the same meaning in your new version of the script as it had in the old version of the script.

You should be able to fix this error by adding the following line of code immediately below the Dim g_objNewTab, g_strHost statement around line 177 of your script:
Set g_objNewTab = crt.GetScriptTab()
Since everything for you will be happening on the already-connected tab that is open before your script is launched, using crt.GetScriptTab() is the right approach for you.

Let me know what additional questions you have after making these adjustments to your script.
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #11  
Old 06-07-2019, 04:16 PM
ecox ecox is offline
Registered User
 
Join Date: Jan 2019
Posts: 38
Exclamation

Hi jdev,

I'm sorry, but I need your help one more time. I'm embarrassed.


Code:
The "Set g_objNewTab = crt.GetScriptTab()" fix the problem..
but now i get a new error...I knew it -.-

So...

In line 687 is an error. The error will be that the session is disconnected after the first host in the hosts.txt

That's not really necessary. An "exit" on the command line is sufficient.
1st) Connect
2nd) Set command and write the result in a * .txt-file
3rd) Disconnect (eg "exit" or "quit")
4th) Connect to 2nd host from hosts.txt
5th) Set command and write the result in a * .txt-file
6th) Disconnect
7th) ....
8th) ...

I try my best and edit this lines, but i get a new error



Code:
https://raw.githubusercontent.com/ec...ster/randl.vbs



EDIT:


With this editing, the script works..wow...
Is this the right way to fix my problem?

greets from germany
ecox
Attached Images
File Type: jpg crt_error_line_687.jpg (68.2 KB, 24 views)
File Type: jpg edit_lines.jpg (31.2 KB, 24 views)
File Type: jpg edit_lines_2.jpg (17.0 KB, 22 views)

Last edited by ecox; 06-07-2019 at 04:37 PM.
Reply With Quote
  #12  
Old 06-07-2019, 04:49 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 914
Quote:
Originally Posted by ecox View Post
I try my best and edit this lines, but i get a new error



EDIT:


With this editing, the script works..wow...
Is this the right way to fix my problem?
Nice work (and good guess) but I don't think that's the correct fix...

For one, you don't need this entire do..loop:
Code:
511                     Do 
512                         crt.Screen.Send "exit" & vbcr 
513                         crt.Sleep 100 
514                     Loop While crt.Screen.WaitForString = "> "
Instead, just send the exit and wait for the jump host shell prompt to arrive. Note that in order to know when the 'exit' command has completed, and you're back at the jump host's shell prompt, you'll need to call WaitForString to look for the jump host shell prompt, which is partly "bash-3.2$". That should be unique enough. For example:
Code:
                    ' Now disconnect from the current machine...
                    crt.Screen.Send "exit" & vbcr
                    ' Wait for the jump host's shell prompt to arrive
                    crt.Screen.WaitForString "bash-3.2$"

                    strSuccesses = strSuccesses & vbcrlf & g_strHost
                End If ' WaitForScreenContentsToStopChanging()
.
.
.
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #13  
Old 06-07-2019, 04:56 PM
ecox ecox is offline
Registered User
 
Join Date: Jan 2019
Posts: 38
Hi jdev,

EDIT:
I still have a very big question.
If a device is not reachable after 3-4 seconds, how can I realize it, then he quits the connection attempt with "Ctrl + C" and continues with the next host?


with your example to fix the problem, does not work for me

Please do not be confused by "bash $" and the new example with ":"

Bash is on work "bash $"
":" at my home...

and what do u replace with

Code:
                    ' Now disconnect from the current machine...
                    crt.Screen.Send "exit" & vbcr
                    ' Wait for the jump host's shell prompt to arrive
                    crt.Screen.WaitForString "bash-3.2$"
EDIT:
ah ok u remove the loop
now works with ur fix thanks ^^

regards

Last edited by ecox; 06-10-2019 at 02:54 AM.
Reply With Quote
  #14  
Old 06-10-2019, 09:33 AM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 914
Quote:
Originally Posted by ecox View Post
I still have a very big question.
If a device is not reachable after 3-4 seconds, how can I realize it, then he quits the connection attempt with "Ctrl + C" and continues with the next host?
SecureCRT is not the app actually making the connection attempt to your secondary host; it's the remote 'ssh' app that's making that connection attempt. So, if you want a time-out condition to take place for the connection attempt and nothing else, then you must find a way to tell the remote 'ssh' app to use a connect timeout that is different than the default.
  • Take a look at the man page for your remote 'ssh' app and see what connection time-out options are available for you there.
  • If you find an option that will tell the remote 'ssh' app to time out more quickly, then run through a scenario manually where you use that command line option and see what the response is like when a time-out condition occurs with a known-down host (clearly you have some known-down hosts because otherwise you wouldn't be asking this question). You'll need to adjust the 'ssh -l ...' command string your Connect() function is sending to include this option.
  • Even if you don't find an option to cut down the connect time out, you'll probably still need to add a Case statement to your Connect() function's Do... WaitForStrings ... Select Case ... Loop in order to handle the scenario where a time-out or non-responsive host condition occurs. Eventually a connection attempt to a non-responsive host will time out with some sort of error text. You will need to add some unique portion of that error text to your vPossibleResponses array and a corresponding Case statement to handle it properly.

Alternatively -- it's not the ideal solution because it's only a time-out scenario for WaitForStrings(), not a true connect time-out -- you could consider adding a time-out parameter to your WaitForStrings() call so that if none of the expected vPossibleResponses are seen within a specific time, the WaitForStrings() call would time out itself, providing you with a Screen.MatchIndex value of zero (0). Adding a Case 0 statement block would allow you to handle the general timeout case, regardless if the timeout was during connection, authentication, etc. For example:
Attached Images
File Type: png ecox_forum_add_timeout_option.png (79.5 KB, 22 views)
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #15  
Old 06-10-2019, 09:59 AM
ecox ecox is offline
Registered User
 
Join Date: Jan 2019
Posts: 38
Hi jdev,

Code

I've included your tips, but unfortunately it gets stuck.
He is waiting for something again? On "^ c"?

When the "^ c" comes, and again the first prompt ":" appears, the script runs indefinitely with "^ c" ... hmm



EDIT:

Code

Now I have done it, I think



is this the right solution ?

regards
ecox
Attached Images
File Type: jpg ERROR_572.jpg (19.6 KB, 20 views)
File Type: jpg fixtit.jpg (52.7 KB, 22 views)

Last edited by ecox; 06-10-2019 at 11:54 AM.
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 09:34 AM.