ReadUntilPrompt throws an exception when term pager is non zero

0 votes
asked Oct 15, 2014 by sujayghosh (360 points)
edited Nov 13, 2014

Using Putty

On typing show version in Putty, I get a screenful of information, followed by ---- More------

The more is the result of the "term pager lines" command set to a non zero value. If the uers sets the "term pager lines" to 0, the ---- More------ shall not be displayed.

Programatically

alt text

I am seeing the above exception when I am trying to ReadUntilPrompt from my program. Probably ReaduntilPrompt cant read the entire output as the ---More--- appears.

Hence, in my C# program I used the following code,to turn off the --- More ---, by setting the term pager to 0 .

 script.SendCommand("term pager lines 0"); 
 script.SendCommand("show version");
 string response = script.ReadUntilPrompt();

 MessageBox.Show(response);

With the above code I am not seeing a string very different from what is outputted by Putty.

alt text

Please let me know how can I solve this problem and get the output just as Putty gives.

PS. If I log into the terminally manually via Putty, and execute the command term pager lines 0", the --- More --- goes away. Then if I run my C# program, it provides the response string similar to that of Putty.

INFORMATION - 12 Nov 2014

The ERROR %Invalid input.. string is shown when the device is not in elevated mode and has the prompt > .

When the prompt is # it is not going through; just replace the > with the # sign in the Detectprompt method provided in the thread.

string line = script.ReadUntil("#" & ScriptEvent.Delay(300));

commented Nov 12, 2014 by Tomas Knopp (58,890 points)
edited Nov 12, 2014

Thanks for the update - if your device operates in two modes of operation with two different prompts (i.e. # in elevated mode and > in the normal mode), then you have to write a regular expression which covers both the possible prompts, see the code below:

script.ReadUntil(ScriptEvent.FromRegex("[#>]") & ScriptEvent.Delay(300));

Please give it a try and if it doesn't work for you send us the newly created log. Without the log we will not be able to help you. Sorry.

commented Nov 13, 2014 by Pavel Matyska (13,480 points)
edited Nov 13, 2014

Thank you for the log. In it I can see that you could successfully call the "show version" command. So I think that the prompt issue is resolved. That said, "it does not work" refer to the --More-- output? In the log I could not find call of "term pager lines 0". In the log there are these steps: log in, determine prompt that ends with #, call "show version" command. From that I think you forgot to call "term page lines 0" command before "show version" command.

commented Nov 13, 2014 by sujayghosh (360 points)
edited Nov 13, 2014

Here are the logs for your investigation.

log_with_termpager_greaterthan_zero - http://pastebin.com/mMX76hev

log_with_termpager_equal_to_zero - http://pastebin.com/6P8CFR14

commented Nov 13, 2014 by Pavel Matyska (13,480 points)
edited Nov 13, 2014

Still could not find the "term pager lines 0" command call. I will post whole code I'm guessing you work with in another answer. It is too long for a comment.

3 Answers

0 votes
answered Oct 16, 2014 by Pavel Matyska (13,480 points)
edited Nov 2, 2014

Hello,

If I understand it correctly, the problem is that the "term pager lines 0" does not take effect when you run it as part of your script?

Anyway, you need to read response after each command. Your script should look like this:

 script.SendCommand("term pager lines 0"); 
 // read response of "term pager lines 0"
 // here you can use script.ReadUntil(<some ScriptEvent>) or 
 // script.WaitFor(<some ScriptEvent>) for your convenience and your needs
 script.ReadUntilPrompt();

 // continue with the next command
 script.SendCommand("show version");
 // read response to process it further
 string response = script.ReadUntilPrompt();

 MessageBox.Show(response);

You are right about ReadUntilPrompt method cant read all output when --More-- appears because the method expects prompt to be in the output. But it never arrives when it stops with --More-- string. Additionally, if the --More-- string is known to be printed to the server, the server can decide to print it first, then move the cursor to the begining of a page and then print the output of the command. But this behaviour can be answered in the verbose log or by making a recording.

commented Oct 25, 2014 by sujayghosh (360 points)
edited Oct 25, 2014

I used the Verbose Log, and the log can be found at http://pastebin.com/FtfSmcSC

commented Oct 27, 2014 by Pavel Matyska (13,480 points)
edited Oct 27, 2014

Hello, the log shows that the server sends "ERROR: %Invalid..." message as a response to "term pager lines 0". The server might be confused by detection of a prompt. Please use putty for the following: send enter, wait 1 sec, send enter, wait 1 sec, send the "term pager lines 0" command and create a log of it. SSH packet logging is what we need. Please send us the log if it contains the same behaviour as when you script it.

commented Nov 2, 2014 by sujayghosh (360 points)
edited Nov 2, 2014

From program - http://pastebin.com/f6wMB9jc

Putty Log - http://pastebin.com/uAWYgvHf

I have changed the device I was SSH ing into .I have used the command term length 0. I am seeing the 1st exception posted in the initial post ; but I can log successfully using Putty.

0 votes
answered Nov 3, 2014 by Pavel Matyska (13,480 points)
edited Nov 10, 2014

Hello, thank you for the logs, but these two reveals less to nothing then the previous one. But, I noticed one thing that is different. Your new SSH device does not have a "space" character as on end of a prompt string. But this should not be the issue.

Please make a putty log with the option check as the image below has and send it to us. We will compare it to the previous program log which had the "ERROR: %Invalid..." error in it.

Putty logging option

commented Nov 3, 2014 by sujayghosh (360 points)
edited Nov 3, 2014

Putty Log - http://pastebin.com/DVQpX7kh

Log from Program - http://pastebin.com/f6wMB9jc

This is a different device, and I am seeing this exception. http://s29.postimg.org/i1fpkrnjr/Rebex_Exception.png

For this device I am not seeing the

http://img.ctrlv.in/img/14/10/15/543ec4c993837.jpg

commented Nov 3, 2014 by Pavel Matyska (13,480 points)
edited Nov 3, 2014

Hello, thank you for the logs. Unfortunately, we do not have enough information from the program log. We are working now on a hotfix with better logging so we can have information such as what prompt is expected to see why there is timeout. Meanwhile, please make sure you are expecting prompt which ends with "#" ( if you are detecting your prompt as we discussed it in http://forum.rebex.net/questions/4757/prompt-string-not-being-detected-by-detectprompt ).

commented Nov 4, 2014 by Pavel Matyska (13,480 points)
edited Nov 4, 2014

Hello, here is the promised hotfix with better logging capabilities. http://www.rebex.net/getfile/6293d0e1110a40018827b1f388108f3f/RebexTotalPack-HotfixBuild5422-Trial-Binaries.zip Please create a new log with it and send it to us again.

commented Nov 10, 2014 by sujayghosh (360 points)
edited Nov 10, 2014

Thanks for the hot fix, but on referencing the DLL's and running the application, I am seeing an SshException - Trial license key not set. See http://ctrlv.in/459435 Please let me know what should I do.

commented Nov 10, 2014 by Tomas Knopp (58,890 points)
edited Nov 10, 2014

Oops, sorry it looks like we forgot to send you a full version of the hotfix by mail (we cannot share the full version hotfixes publicly for obvious reasons but we sent them only to customers with active Support Contract through email). I will be sending the link via email to you in a few minutes.

+1 vote
answered Nov 13, 2014 by Pavel Matyska (13,480 points)
edited Nov 13, 2014

Here is a code I believe you work with.

        var sshVar = new Ssh();
        sshVar.Connect("ipaddres");
        sshVar.Login("uid", "pwd");

        sshVar.LogWriter = new Rebex.FileLogWriter(@"c:\rebexlog\log.txt", Rebex.LogLevel.Verbose);

        Scripting script = sshVar.StartScripting();
        script.WaitFor(ScriptEvent.AnyText);

        try
        {
            // determine detect prompt
            DetectPrompt(script);

            // this command call is not found in any log!
            script.SendCommand("term pager lines 0");

            // read response of "term pager lines 0"
            // here you can use script.ReadUntil(<some ScriptEvent>) or 
            // script.WaitFor(<some ScriptEvent>) for your convenience and your needs
            script.ReadUntilPrompt();

            // continue with the next command
            script.SendCommand("show version");
            // read response to process it further
            string response = script.ReadUntilPrompt();

            MessageBox.Show(response);
        }
        catch (Exception exception)
        {
            MessageBox.Show(exception.Message);
            throw;
        }

I believe this is your DetectPrompt method you work with now:

    private static void DetectPrompt(Scripting script)
    {
        string promptLine = "";

        while (true)
        {
            string line = script.ReadUntil(ScriptEvent.FromRegex("[>#]") & ScriptEvent.Delay(300));

            line = line.TrimStart();

            if (line != promptLine)
            {
                script.Send(FunctionKey.Enter);
                promptLine = line;
            }
            else
            {
                script.Prompt = "string:" + promptLine;
                break;
            }
        }
    }

What do you get from this code?

commented Nov 13, 2014 by sujayghosh (360 points)
edited Nov 13, 2014

Pavel I am sorry , the term pager command is different for different devices, I was uanaware of that so the Rebex command are working. I confirmed this by matching with Putty

I think the only bug here is that Detectprompt is not working properly ; solution from Tomas solves that, and now I can read the data.

commented Nov 13, 2014 by Tomas Knopp (58,890 points)
edited Nov 13, 2014

Thanks for info. We are glad the problem is solved now!

commented Nov 13, 2014 by sujayghosh (360 points)
edited Nov 13, 2014

Tomas - I just found there are cases when its not working. I shall send a detailed information via email tomorrow , as this thread has several other information , which may get mixed up.

...