0 votes
by (330 points)
edited

Hello.

I have some problems using DetectPrompt() method. My real prompt string is "[username@servername ~]$ " (without ").

Case 1:

var ssh = new Ssh();

ssh.Connect(servername);
ssh.Login(username, password);

Scripting scripting = ssh.StartScripting();

//Autodetecting
scripting.DetectPrompt();
//scripting.Prompt returns "regex:[username@servername ~][$] $" value (without ")

scripting.SendCommand("whoami");

string response = scripting.ReadUntilPrompt(); //freeze and timeout exception !!!

Case 2:

ssh.Connect(servername);
ssh.Login(username, password);

Scripting scripting = ssh.StartScripting();

//Manual setting value from Case 1.
scripting.Prompt="regex:[username@servername ~][$] $"

string response = scripting.ReadUntilPrompt(); //Freeze and timeout exception !!!

Case 3:

ssh.Connect(servername);
ssh.Login(username, password);

Scripting scripting = ssh.StartScripting();

//Setting value from Case 1, but manual escaping some characters.
scripting.Prompt="regex:\\[username@servername ~\\][\\$] $"

string response = scripting.ReadUntilPrompt(); //ALL GOOD!!! Response returns welcome message: "Last login ...".
by (330 points)
edited

Case 4 (changing real prompt string to "servername:~ # "):

var ssh = new Ssh();

ssh.Connect(servername);
ssh.Login(username, password);

Scripting scripting = ssh.StartScripting();

//Autodetecting
scripting.DetectPrompt();
//scripting.Prompt returns "regex:servername:~ # $" value (without ")

scripting.SendCommand("whoami");

string response = scripting.ReadUntilPrompt(); //ALL GOOD !!!

5 Answers

+1 vote
by (15.2k points)
edited
 
Best answer

Hello,

thank you for bringing this bug to our attention! I have added support for these prompt scenarios. You can download the hotfix here: download hotfix

by (15.2k points)
edited

I have just fixed the hotfix download link.

0 votes
by (330 points)
edited

Hello. Thanks for the hotfix! But now, i have some problems with assemblies while using new Rebex.Common.dll from this hotfix.

var ssh = new Ssh();

FileLoadException: Could not load file or assembly 'Rebex.Common, Version=2.0.5298.0, Culture=neutral, PublicKeyToken=1c4638788972655d' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040).

Hotfix net-4.0:

  1. Rebex.Common 2.0.5381.1
  2. Rebex.Time 3.0.5381.1

My current installed trial version net-4.0:

  1. Rebex.Common 2.0.5298.0
  2. Rebex.Networking 3.0.5298.0
  3. Rebex.SshShell 1.0.5298.0
  4. Rebex.Terminal 1.0.5298.0
by (15.2k points)
edited

Hello,

please remove all references to Rebex dll's from your project and add them again targeting the hotfix assemblies.

by (58.9k points)
edited

Sorry, there was a mistake on our side. We will post a Virtual Terminal hotfix here within minutes for you to download.

by (15.2k points)
edited
by (330 points)
edited

The last hotfix works perfectly! Thank you very much.

0 votes
by (330 points)
edited

Hello, i have new problem using DetectPrompt() method.

I modified the file /home/username/.bashrc on my linux system.

I added next strings:

sleep 10 seconds

sleep 10

print some text after standard welcome message, for example:

Last login: Mon Sep 29 10:54:19 2014 from 192.168.0.21

test

echo "test"

Case 1:

var ssh = new Ssh();

ssh.Timeout = 200000; //200 seconds

ssh.Connect(servername);
ssh.Login(username, password);

Scripting scripting = ssh.StartScripting();

//scripting.Timeout have default value: 60000
scripting.DetectPrompt();

The ssh timeout value > the scripting timeout value > the script sleep value. I got:

Rebex.TerminalEmulationException: Unable to detect prompt

in Rebex.TerminalEmulation.Scripting.KC()
in Rebex.TerminalEmulation.Scripting.DetectPrompt()

Case 2 (script sleep value modified to 3 seconds):

var ssh = new Ssh();

ssh.Timeout = 1000; //1 second

ssh.Connect(servername);
ssh.Login(username, password);

Scripting scripting = ssh.StartScripting();
scripting.Timeout = 1000
scripting.DetectPrompt(); // WORKS !!!

Is it correct?

+1 vote
by (15.2k points)
edited

Hello, Yes, it is correct. Scripting.DetectPrompt() tries to read some input in short chunks of time and when nothing is read, it throws this exception. If you need to wait before Scripting.DetectPrompt() you can use

// wait for 10 seconds
scripting.WaitFor(ScriptEvent.Delay(10 * 1000));

// now try to detect prompt
scripting.DetectPrompt();

or if the 'sleep' time is not known but you know there is some, you can try to wait for first character and then try to detect prompt

// wait for first character
// this will timeout after Scripting.Timeout period of time
scripting.WaitFor(ScriptEvent.AnyText);

// now try to detect prompt
scripting.DetectPrompt();
+1 vote
by (15.2k points)
edited

Hello, yes, it is correct. As I said before, the DetectPrompt() method try to read from the server in short chunks of time. None of these read attempts does timeout because the chunks are smaller then 1 second. DetectPrompt is in fact small script using Scripting API and the Scipting.Timeout property affects its parts, not the whole method.

by (330 points)
edited

Thanks for answers.

...