0 votes
by (170 points)
edited

We occasionally use a Telnet Shell to run some shell commands on an AIX box. After successfull login, we immediately change the prompt via an export PS1 command sent to the shell. We also set the shell prompt accordingly.

For example, in C# we do this:

shell.Prompt= "$XYZ$";

shell.SendCommand(@"export PS1=""$XYZ$""");

This works fine, as long as the prompt length is pretty short. That is, after executing the above, I can send commands, and get their output, and the shell is able to figure out where the end of each output is, based on the prompt string.

This has worked just fine with a number of shell commands. However, recently we attempted to execute a copy command (e.g. cp somefile1 somefile2), and the command consistently fails unless the prompt is10 characters or less. So, for example ":PROMPTXY:" will work, but ":PROMPTXYZ:" will not. Some other commands that we have tried do not seem to care (e.g. ls -l). The only difference we could see was that the copy command does not normally return any output to the shell.

An error occurs when we attempt to send the copy command to the shell (via shell.SendCommand(...)). The exeception thrown by Rebex says "Unable to process command", which I am guessing means there was a problem synchronizing on the prompt.

Any ideas what is going on here?

3 Answers

0 votes
by (73.6k points)
edited
 
Best answer

There is no limit on prompt length. Can you please send us the session log in Verbose level to support@rebex.net for detailed investigation of the issue?

It can be produced as shown bellow.
Please note it can contain sensitive data, so I suggest you to assign the LogWriter property just after the login sequence, or edit the log file manually.

// start shell
Telnet client = new Telnet("host");
Shell shell = client.StartShell();
shell.Prompt = "prompt";

// log in
shell.ReadAll(": ");
shell.SendCommand("username");
shell.ReadAll(": ");
shell.SendCommand("password");

// assign logger
client.LogWriter = new Rebex.FileLogWriter("C:/temp/telnet.log", LogLevel.Verbose);

// read welcome message
shell.ReadAll();

// do some work
shell.SendCommand("ls");
shell.ReadAll();
by (170 points)
edited

Thanks for your reply. I will get a verbose log for you, but it will probably take a couple of days to get around to it.

by (73.6k points)
edited

Thanks, it is not a problem for us.

Actually, there is one alternative to the Shell class you may be interested in. Please try to use the VirtualShell class which is a helper class wrapping the VirtualTerminal class. Download VirtualShell.zip.

Instead of Shell shell = client.StartShell() call VirtualShell shell = new VirtualShell(client.StartVirtualTerminal())

by (170 points)
edited

I'm going to accept this as the answer to my question about limit on prompt length. That is, there is no limit. We are still having issues with prompt length, and also if we try to send a command that is "too long". We think it has something to do with the terminal type, so I will try the Virtual Terminal and see if that works for us. If it does, I will post a comment here to confirm.

by (73.6k points)
edited

Thank you, posting a comment is appreciated.

Please note, that terminal type can be specified using the TerminalOptions.TerminalName property. However terminal type is negotiated just after the connection is established, so you have to set the property before you start the VirtualTerminal. It can be done as follows:

TerminalOptions options = new TerminalOptions();
options.TerminalName = "vt100";

Telnet client = new Telnet("server");
VirtualTerminal vt = client.StartVirtualTerminal(options, 80, 25);
0 votes
by (160 points)
edited

I ran into this issue as well.

When calling the below it seems to not like more than 74 characters

shell.SendCommand(command);

However, if you change the line to the below, i havent found the limit

shell.SendCommand(command,true);
by (73.6k points)
edited

Can you please send us the Verbose log as shown above? Please email it to support@rebex.net

0 votes
by (15.2k points)
edited

Hi, we have just release new Scripting API in 2014-R2 release. You can read more of its features on Scripting features page.

...