Closed JamesParrott closed 6 months ago
Fixed it. The issue occurs due to throwing a multiline string at stdin. This fix throws nsh one command at a time and it works fine. There could be a tricky buffering / stream /stdin flushing issue, but perhaps it might be decided to support multi-line string inputs in future.
try:
for command in '''\
ls -l
echo !!
echo $0
exit
'''.split('\n'):
stdin, stdout, stderr = con.exec_command(command)
print(stdout.read())
except paramiko.ssh_exception.AuthenticationException as e:
print(e)
finally:
con.close()
[edit] Apologies. The hang only occurs when sshing in with Paramiko, a Python library. This bug is an even smaller niche, and even lower priority for you guys therefore, but I'll leave it up for posterity.
Hi there,
I've been running some tests, ssh-ing into a local Docker container from Python, using multiple shells. When I try as a user whose shell is nsh, the test script hangs.
It's entirely possible I've misconfigured nsh, or encountered one of those strange Musl Alpine bugs. And it's even more likely, there's an issue in my Python code.
However I can successfully connect with Paramiko, as users whose shells are: bash , dash , fish , zsh , ion-shell , tcsh , oksh , loksh , yash, and from edge/testing: elvish , xonsh , mrsh and imrsh (and csh, ksh, rc, and a source build of heirloom-sh on Debian).
I first thought this was a general ssh issue, but it only occurs in my script. It would be above and beyond the call of duty for someone to debug my Python code, especially on a great repo you could all be working on anyway, that uses a different language. But nonetheless, I wondered why I've been unable to get the script to work for nsh, (I've had no joy with hilbish or nushell either).
To reproduce (some shells not installed for brevity):
Dockerfile:
Build image:
Run container (blocks process to show output from server):
Install paramiko, preferably after first making and activating a venv (requires Python).
Run test script:
I know I can just docker exec in instead. It's a long story, and besides the point, why I want to ssh to containers. But lets do that, to show nsh is otherwise working, and to check the path of the nsh binary:
remember some characters from the start of the container_id, then the following commands:
respectively produce:
To kill the container when done: