Hi,
I was unable to watch the wideo as it the server says: Screencast not found.
Anyway, you should change the DetectPrompt method to this:
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;
}
}
}
Please note the change in the
string line = script.ReadUntil(ScriptEvent.FromRegex("[>#]") & ScriptEvent.Delay(300));
line of code. This will detect your prompt when it changes from '>' ending char to '#' char. Also make sure that you call this DetectPrompt after you expect the prompt change. In most cases after each call of script.SendCommand(...)
method you should somehow read the command response and not stack unread responses. That can lead to invalid results when expecting somethig after the last command, but it appears in one of the previous responses.
This said, you shoud end up with this method:
string response;
var sshVar = new Ssh();
sshVar.Connect(ipaddress);
sshVar.Login(userid, password);
sshVar.LogWriter = new Rebex.FileLogWriter(@"c:\rebexlog\log.txt", Rebex.LogLevel.Verbose);
Scripting script = sshVar.StartScripting();
script.WaitFor(ScriptEvent.AnyText);
try
{
DetectPrompt(script);
}
catch (Exception exception)
{
throw;
}
script.SendCommand("enable");
// read response until the "Password:" prompt appears
script.ReadUntil("Password:");
// send second level password
script.SendCommand(password);
// prompt has changed, detect what it looks like now
DetectPrompt(script);
script.SendCommand("term pager lines 0");
// after each SendCommand, read the response.
script.ReadUntilPrompt();
try
{
script.SendCommand("show interface");
**response = script.ReadUntilPrompt();**
}
catch (Exception e)
{
Console.WriteLine("{0}", e.Message);
throw;
}
Please note that second DetectPrompt(script)
call is right after the "Password:" command to detect new prompt. I also added reading response of "term pager lines 0" command.