Closed TRosier closed 1 year ago
@TRosier Can you please clarify? When you log into the UUT using Putty, are you receiving a "peek command not found"?
It sounds like you may have installed the package that contains the "peek" and "poke" commands for a single user instead of globally for all users. What distribution of Linux is your UUT running? What steps did you take to install the "peek" and "poke" commands?
@volks73, When I am using Putty all is operating as designed. I send a peek with an address and I get register values back. When I use LibSSH2, I am getting the command not available response. I can login using many instances of Putty and the command is successful. Peek and Poke commands respond accordingly. That is not the case using LibSSH2 with all other connections closed. The peek and poke commands are installed with the version of Linux that we are using on our hardware. I would have to check and see what version it is, I am sure it is stripped down whatever it is, however with Putty, I am not seeing this issue.
@TRosier, I think PuTTY is loading a different environment than the LIBSSH2 shell channel. When you log into the UUT with PuTTY, PuTTY probably reads a .profile
, .bashrc
, .env
, .bash_profile
, .login
, .bash_login
, etc. file that sets various environment variables. One of these environment variables, PATH
, is probably adding a path to binaries installed somewhere, possibly /home/root/.local/bin
. Maybe this is where the peek
and poke
commands are located? In PuTTY, can you do a which peek
command and note the path that appears? With PuTTY, can you run echo $PATH
and note the contents that are printed?
The LIBSSH2 shell channel does not read any of these files automatically and does not set any environment variables. Again, it is very low-level and a full-feature shell, like PuTTY, is beyond the scope of this toolkit. However, if you can identify the location of the peek and poke commands and determine the missing path in the PATH
environment variable, you could add the missing path to the PATH
environment variable with export PATH="<missing path>:$PATH
as a command after connecting with LIBSSH2. It is also possible to do a source ~/.bashrc
or similar after connecting with LIBSSH2 to "source" the environment.
Another option is after noting the path from the which peek
command, you could just use the absolute path with LIBSSH2. For example, if the which peek
command returned /home/root/.local/bin/peek
, then you can use /home/root/.local/bin/peek
instead of just peek
.
@volks73, below are the responses from my UUT after connecting with Putty and sending the commands you requested.
root@iDirect ~ # which peek /opt/idirect/bin/peek root@iDirect ~ # root@iDirect ~ # root@iDirect ~ # echo $PATH /usr/local/bin:/usr/bin:/bin:/opt/idirect/bin:/usr/local/sbin:/usr/sbin:/sbin root@iDirect ~ #
@TRosier The /opt/idirect/bin
is a "non-standard" path. When you connect using the LIBSSH2 the /opt/idirect/bin
is most likely not in the PATH
but added as part of a .bashrc
, .sh
, .profile
, etc. file. Can you connect using LIBSSH2 and issue the echo $PATH
command? My guess is that /opt/idirect/bin
will not be in the output.
If my guess is correct, then you have a couple of options:
/opt/idirect/bin/peek
and /opt/idirect/bin/poke
for the commands when using LIBSSH2.export PATH="/opt/idirect/bin:$PATH"
command as the first command after connecting to the UUT using LIBSSH2/opt/idirect/bin
to the PATH
and then send source <path/to/rc/file>
as the first command after connecting to the UUT using LIBSSH2/opt/idirect/bin/peek
and /opt/idirect/bin/poke
to a "standard" path location, /usr/bin
or /usr/local/bin
. This should put peek
and poke
in the path for LIBSSH2, but I am not 100% confident about this one and there could be weird side effects. Permissions would have to be properly setup as well. Basically, this is an option of last resort.@volks73, outstanding. Got it working via your suggestion but with a slight twist. This is the output you asked about sending echo $PATH, /usr/bin:/bin:/usr/sbin:/sbin. It does work sending the command /opt/idirect/bin/peek and /opt/idirect/bin/poke. What I did to make that easier is moved the peek/poke commands to the last directory indicated by the echo $PATH command response. I moved them to /sbin. Now I can send the peek/poke commands alone with no issues. This is for an engineering task so not something that needs to be kept track of for the field. I appreciate the insight and the help with this issue.
@TRosier Great to hear. I am glad you were able to get your issue resolved. I am closing this issue.
I read trough "SSH read sometimes not working #48" as I could not get responses from two commands I am using. I found that those two commands, peek/poke, are using the stderr channel as described in the issue mentioned above. I can log into my UUT and send pwd, ls, etc and get the expected responses. When I look at stderr for the peek and poke commands I receive "peek command not found." I get the same for the poke command. I noticed when I investigate my UUT it is using the /home/root/ directory by default. I log into the same directory using Putty and the peek/poke commands work as designed. If someone could let me know what I may be doing wrong, I would appreciate it.
V/r, Troy