0 votes
by (400 points)
edited by

Hello. I have a question about Scripting mechanism.

I got the following result after executing SSH command.

2016-11-18 13:31:15.630 VERBOSE Ssh(1)[10] Info: Received data: 
 0000 |1B-5B-34-32-44-20-20-20 20-20-20-20-20-20-20-20| .[42D           
 0010 |20-20-20-20-20-20-20-20 20-20-20-20-20-20-20-20|                 
 0020 |20-20-20-20-20-20-20-20 20-20-20-20-20-20-20-1B|                .
 0030 |5B-34-32-44                                    | [42D
2016-11-18 13:31:15.630 VERBOSE VirtualTerminal(0)[10] Scripting:     WaitFor: polling data for max 50 ms.
2016-11-18 13:31:15.644 VERBOSE Ssh(1)[12] SSH: Received packet SSH_MSG_CHANNEL_DATA (51 bytes).
 0000 |5E-00-00-00-00-00-00-00 2A-20-6E-74-70-2D-73-65| ^.......* ntp-se
 0010 |72-76-69-63-65-20-75-6E 69-63-61-73-74-2D-73-65| rvice unicast-se
 0020 |72-76-65-72-20-31-39-32 2E-31-36-38-2E-31-30-30| rver 192.168.100
 0030 |2E-32-38                                       | .28

Scripting.ReceivedData return:

"                                           ntp-service unicast-server 192.168.100.28"

or

"42D                                          42D ntp-service unicast-server 192.168.100.28"

I tried to use all terminal types (Ansi, Wyse60, Pick, VT52).

I expect to see:

" ntp-service unicast-server 192.168.100.28"

(all without double quotes)

Does the Scripting mechanism support "1B-5B-xx-xx-44" (ESC[nD) sequence? How i can properly use it?

1 Answer

0 votes
by (15.2k points)

Hello,

before I answer your question, here are some notes about shell or terminal in general. Shell is not a protocol, that can be scripted easily as its intended use is to show output to the human user on the terminal screen. How the output is printed (sent to the client terminal) is exclusively up to the server. The client terminal have to understand the server output and interpret it. In your case, your server uses line of spaces to "erase" current line followed by cursor move escape sequence. So the user will see only the output that follows those spaces (as you wrote that you expect "ntp-service..."). Your server also could send escape sequence, that erase line by its meaning, instead of sending many spaces. It also can send the line written backwards with proper escape sequences in between the characters. All that matter is what the human will see.

Now to the actual answer. Scripting class returns what was received as a data, but do not interpret escape sequences. It simply omits all escape sequences from ReceivedData property. VirtualTerminal class or TerminalControl class represents terminal screen and so they also interpret escape sequences. You can use Scripting.Terminal property to get a terminal bound to the same SSH session as the Scripting class. It has Screen property, that can help you determine, what the user actually "see". Or you may use different ScriptEvent to "get rid off" the spaces or simply trim them.

...