I'm trying Rebex SSH Pack to write an application that executes a lot of interactive commands on many linuces and unices platforms.
While testing prompt interactions with Rebex.TerminalEmulation.Shell objects, an error executing a "su -" command interaction on OpenBSD 4.7 occurs. I think there is a problem related with the prompt options.
The following code is OK on Linux, Solaris and HP-UX.
Rebex.Net.Ssh ssh;
Rebex.TerminalEmulation.Shell shell;
String terminalScreen;
String host;
String username;
String password;
String rootPassword;
String[] promptQuestions;
try
{
host = "XXX.XXX.XXX.XXX";
username = "user";
password = "password";
rootPassword = "rootpassword";
promptQuestions = new String[] { "Password:", "Password: " };
ssh = new Rebex.Net.Ssh();
ssh.LogWriter = new Rebex.FileLogWriter(@"C:\temp\rebex.txt", Rebex.LogLevel.Debug);
ssh.Connect(host);
ssh.Login(username, password);
ssh.Timeout = 5000;
//shell = ssh.StartShell(Rebex.TerminalEmulation.ShellMode.Prompt);
//shell.Prompt = "regex:[$#] $";
shell = ssh.StartShell(Rebex.TerminalEmulation.ShellMode.WellKnownShell);
shell.SendCommand("su -");
while (shell.IsRunning)
{
terminalScreen = shell.ReadAll(promptQuestions);
foreach(String promptQuestion in promptQuestions)
if (terminalScreen.Contains(promptQuestion))
{
shell.SendCommand(rootPassword, true);
break;
}
}
}
catch (Exception e)
{
}
The text above describes two error scenarios with the ssh log attached.
ShellMode.Prompt
shell.Prompt = "regex:[$#] $";
Error:
code: shell.SendCommand("su -");
message: Unable do process command
2011-02-28 15:45:31.995 Opening log file.
2011-02-28 15:45:42.542 DEBUG Ssh(1) Info: Received 514 bytes of data.
2011-02-28 15:45:42.542 DEBUG Ssh(1) Info: Sent 5 bytes of data.
2011-02-28 15:45:42.542 DEBUG Ssh(1) Info: Received 7 bytes of data.
2011-02-28 15:46:35.166 Opening log file.
2011-02-28 15:46:35.791 INFO Ssh(1) Info: Connecting to XX.XX.XX.XX:22 using Ssh 1.0.4060.0 (trial version).
2011-02-28 15:46:35.838 DEBUG Ssh(1) SSH: Server is 'SSH-2.0-OpenSSH_5.5'.
2011-02-28 15:46:35.838 DEBUG Ssh(1) SSH: Negotiation started.
2011-02-28 15:46:35.869 DEBUG Ssh(1) SSH: Group exchange.
2011-02-28 15:46:35.869 DEBUG Ssh(1) SSH: Negotiating key.
2011-02-28 15:46:36.026 DEBUG Ssh(1) SSH: Validating signature.
2011-02-28 15:46:36.057 DEBUG Ssh(1) SSH: Negotiation finished.
2011-02-28 15:46:36.057 INFO Ssh(1) Info: Server: SSH-2.0-OpenSSH_5.5
2011-02-28 15:46:36.057 INFO Ssh(1) Info: Fingerprint: XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX
2011-02-28 15:46:36.057 INFO Ssh(1) Info: Cipher info: SSH 2.0, DiffieHellmanGroupExchangeSHA1, DSS, aes256-ctr/aes256-ctr, SHA1/SHA1
2011-02-28 15:46:36.916 DEBUG Ssh(1) SSH: Allowed authentication methods: publickey, password, keyboard-interactive.
2011-02-28 15:46:36.916 DEBUG Ssh(1) SSH: Trying password authentication for 'user'.
2011-02-28 15:46:36.948 DEBUG Ssh(1) SSH: Authentication successful.
2011-02-28 15:46:37.573 DEBUG Ssh(1) SSH: Requesting pseudoterminal 'vt100' (80x25).
2011-02-28 15:46:37.573 DEBUG Ssh(1) SSH: Requesting shell.
2011-02-28 15:46:38.588 DEBUG Ssh(1) Info: Received 514 bytes of data.
2011-02-28 15:46:38.588 DEBUG Ssh(1) Info: Sent 5 bytes of data.
2011-02-28 15:46:38.588 DEBUG Ssh(1) Info: Received 7 bytes of data.
ShellMode.WellKnownShell
error:
code: terminalScreen = shell.ReadAll(promptQuestions);
message: Response reading timeout
terminal error message: "tset: standard error: Inappropriate ioctl for device"
2011-02-28 15:53:43.051 Opening log file.
2011-02-28 15:53:43.176 INFO Ssh(1) Info: Connecting to XX.XX.XX.XX:22 using Ssh 1.0.4060.0 (trial version).
2011-02-28 15:53:43.208 DEBUG Ssh(1) SSH: Server is 'SSH-2.0-OpenSSH_5.5'.
2011-02-28 15:53:43.208 DEBUG Ssh(1) SSH: Negotiation started.
2011-02-28 15:53:43.239 DEBUG Ssh(1) SSH: Group exchange.
2011-02-28 15:53:43.239 DEBUG Ssh(1) SSH: Negotiating key.
2011-02-28 15:53:43.395 DEBUG Ssh(1) SSH: Validating signature.
2011-02-28 15:53:43.426 DEBUG Ssh(1) SSH: Negotiation finished.
2011-02-28 15:53:43.426 INFO Ssh(1) Info: Server: SSH-2.0-OpenSSH_5.5
2011-02-28 15:53:43.426 INFO Ssh(1) Info: Fingerprint: XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX
2011-02-28 15:53:43.426 INFO Ssh(1) Info: Cipher info: SSH 2.0, DiffieHellmanGroupExchangeSHA1, DSS, aes256-ctr/aes256-ctr, SHA1/SHA1
2011-02-28 15:53:43.614 DEBUG Ssh(1) SSH: Allowed authentication methods: publickey, password, keyboard-interactive.
2011-02-28 15:53:43.614 DEBUG Ssh(1) SSH: Trying password authentication for 'user'.
2011-02-28 15:53:43.645 DEBUG Ssh(1) SSH: Authentication successful.
2011-02-28 15:53:43.645 DEBUG Ssh(1) SSH: Requesting shell.
2011-02-28 15:53:43.661 DEBUG Ssh(1) Info: Sent 21 bytes of data.
2011-02-28 15:53:43.661 DEBUG Ssh(1) Info: Received 16 bytes of data.
2011-02-28 15:53:43.676 DEBUG Ssh(1) Info: Sent 30 bytes of data.
2011-02-28 15:53:43.676 DEBUG Ssh(1) Info: Received 17 bytes of data.
2011-02-28 15:53:43.676 DEBUG Ssh(1) Info: Sent 31 bytes of data.
2011-02-28 15:53:43.676 DEBUG Ssh(1) Info: Received 20 bytes of data.
2011-02-28 15:53:43.676 DEBUG Ssh(1) Info: Sent 34 bytes of data.
2011-02-28 15:53:43.676 DEBUG Ssh(1) Info: Received 15 bytes of data.
2011-02-28 15:53:43.676 DEBUG Ssh(1) Info: Sent 39 bytes of data.
2011-02-28 15:53:43.676 DEBUG Ssh(1) Info: Received 15 bytes of data.
2011-02-28 15:53:43.676 DEBUG Ssh(1) Info: Sent 33 bytes of data.
2011-02-28 15:53:43.692 DEBUG Ssh(1) Info: Received 9 bytes of data.
2011-02-28 15:53:43.786 DEBUG Ssh(1) Info: Sent 13 bytes of data.
2011-02-28 15:53:43.833 DEBUG Ssh(1) Info: Received 54 bytes of data.
I would appreciate some help. Thank you.