fieldrndservices / libssh2-labview

A LabVIEW library for SSH client support via libssh2
Apache License 2.0
22 stars 2 forks source link

Not Receiving All Data From Query #68

Closed TRosier closed 2 months ago

TRosier commented 2 months ago

There is a small program that we are running on a Linux server. When logged using Putty the output is shown below:

..# ./dump_burst -p 3305 -d eth1 -c g -n 1 FILTER STR udp port 3305 and ip[39] & 0x1 == 1

TIME BT MO SP MB CRC    NCR-MSB    NCR-LSB IGID INID   SNUM  SYMRATE        SNR    SNR(dB)  FREQOFF   TIMING 0xHDLC KA
---- -- -- -- -- ---    -------    ------- ---- ----   ----  -------        ---        ---  -------   ------ ---- --

00000012 TD 8 00 00 001 0x00000338 0x7ed7b208 0001 0004 0x0f52 04000000 0x1b9c18d0 13.7253 -0000061 -0000001 0x8004 1 Did not match got ./dump_burst expected dumpburst******

When we use the ssh2 VIs below this is all we are getting :

FILTER STR udp port 3305 and ip[39] & 0x1 == 1

Did not match got ./dump_burst expected dump_burst

We are getting the first and last lines of the output. At first I thought it may be a superuser issue but running in Putty w/o being in superuser mode give the same type of output showing the missing data when using the ssh2 VIs. Not all the data is there but there is still some between the fist and last lines. That is shown below.

$ ./dump_burst -p 3305 -d eth1 -c g -n1 FILTER STR udp port 3305 and ip[39] & 0x1 == 1

TIME BT MO SP MB CRC    NCR-MSB    NCR-LSB IGID INID   SNUM  SYMRATE        SNR    SNR(dB)  FREQOFF   TIMING 0xHDLC KA
---- -- -- -- -- ---    -------    ------- ---- ----   ----  -------        ---        ---  -------   ------ ---- --

Couldn't open device eth1: socket: Operation not permitted Did not match got ./dump_burst expected dump_burst

Any help with this would be appreciated.

volks73 commented 2 months ago

Can you please share a simplified VI snippet that recreates the issue?

My guess is that you need to use the Write Terminal.vi and specify a terminal.

These kinds of issues arise because PuTTY is establishing a terminal channel and a shell into the remote system. This means a lot of the environment and "plumbing" is handled implicitly by PuTTY. In contrast, this Toolkit is a low-level toolkit that minimizes any implicit actions. The toolkit is also for programmatic access, not necessarily an interactive shell.

Have you tried the Read-Execute-Print-Loop with a Raspberry Pi.vi example? Despite the name, any remote SSH server can be used. It does not need to be a Raspberry Pi.

TRosier commented 2 months ago

Thank you for the response. I believe I have attached the snippet you requested. I have not had a chance to look at https://github.com/fieldrndservices/libssh2-labview/blob/main/src/Examples/Read-Execute-Print-Loop%20with%20a%20Raspberry%20Pi.vi, however I will take a look at it soon.

TRosier commented 2 months ago

I downloaded the VI. There are a lot of VIs that the main one cannot find. I believe they are SSH VIs and I have the SSH2 package installed.

volks73 commented 2 months ago

I believe I have attached the snippet you requested.

I do not see any VI snippet in the comments for this issue. Can you please try again?

I downloaded the VI. There are a lot of VIs that the main one cannot find. I believe they are SSH VIs and I have the SSH2 package installed.

The VI is provided as an Example in the Example Finder within the LabVIEW development environment. I just provided a link to the VI in the repository for reference. If you have installed the package, then the example VI should be available within the development environment.

TRosier commented 2 months ago

Sorry about that, the block diagram I am using should now be attached. I am going to work on getting the example VI loaded up. Block_Diagram

TRosier commented 2 months ago

Hi Chris, So I have the output of the command from Putty...

./dump_burst -p 3305 -d eth1 -c g -n 1 FILTER STR udp port 3305 and ip[39] & 0x1 == 1

TIME BT MO SP MB CRC NCR-MSB NCR-LSB IGID INID SNUM SYMRATE SNR SNR(dB) FREQOFF TIMING 0xHDLC KA


00000012 TD 8 00 00 001 0x00000338 0x7ed7b208 0001 0004 0x0f52 04000000 0x1b9c18d0 13.7253 -0000061 -0000001 0x8004 1 Did not match got ./dump_burst expected dump_burst

Then I have the output from the VI you referenced...

VI_Output

So I am getting the same thing from the Read-Execute...VI that I am from the VI I am using initially. The first and last lines are returned and the data needed in the middle is not.

volks73 commented 2 months ago

I wonder if the data in the middle is on STDERR instead of STDOUT? Your VI and the example are only reading STDOUT. Can you try adding reading STDERR?

PuTTY, and most terminals/shells, will "mix" STDOUT and STDERR writing to the terminal.

TRosier commented 2 months ago

So that did it, the missing data is being sent on STDERR. So thank you for the help with that. I appreciate it. One piece left is I have to read this after logging in as super user. That requires a login then sending a su - and another pw. I remember there is a way to send multiple command but not sure how to do it. Any advice for that?

TRosier commented 2 months ago

OK so I have all of this figured out now. I searched and found https://github.com/fieldrndservices/libssh2-labview/issues/5 which I used as a reference. I can now log on and invoke super user mode. From there I can run the command and get the expected output. The only thing that is strange and I was trying understand why, is that there was no output in this case with STDERR. I had to put the READ back in place and then remove the ./ from the ./dump_burst -p 3305 -d eth1 -c g -n 1 command. I can share a snippet of the block diagram if you're interested. Otherwise, I appreciate the help and this issue can be closed.

volks73 commented 2 months ago

Great! I am glad you were able to resolve all of your issues. Please share the block diagram so others that may encounter a similar issue in the future will benefit. Thank you.

No output on STDERR might be unrelated to this toolkit and related to executing commands in a superuser subshell, su -u. STDERR might need to be manually redirected to the terminal or parent shell when using a superuser sub-shell.

TRosier commented 2 months ago

Ok man, thanks for all the help. Below is the block diagram. It is not optimized but should be readable to anyone that encounters the same issue. SSH2_Shell_Example