Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't execute background process on remote server #235

Open
bradhvr opened this issue Jan 13, 2022 · 1 comment · May be fixed by #239
Open

Can't execute background process on remote server #235

bradhvr opened this issue Jan 13, 2022 · 1 comment · May be fixed by #239

Comments

@bradhvr
Copy link

bradhvr commented Jan 13, 2022

  • Python 3.9.1
  • jumpssh==1.6.5
  • paramiko==2.9.2

When I try to run a remote SSH command as a background process, it doesn't work. The command returns successfully, but the response is blank and it is as if the command was never run. When I run the same command with Paramiko, it works.

Here's a sample script that connects to the given ip and writes the date to a log file as a background process. If you run it, you'll see it works using Paramiko but no log file is created with JumpSSH.

import os
import paramiko
from jumpssh import SSHSession

HOST = '<server ip>'
USER = '<server username>'
ID_FILE = '<path to ssh key>'
CMD = 'date > {}.log &'


print("Using Paramiko\n=========================")
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

private_key = paramiko.RSAKey.from_private_key_file(os.path.expanduser(ID_FILE))
ssh_client.connect(hostname=HOST, username=USER, pkey=private_key)
stdin, stdout, stderr = ssh_client.exec_command(CMD.format('paramiko'))

out = stdout.read().decode().strip()
error = stderr.read().decode().strip()

ssh_client.close()
print("Out: {}\nError: {}".format(out, error))

print("\nUsing jumpssh\n=========================")
gateway_session = SSHSession(HOST, USER, private_key_file=os.path.expanduser(ID_FILE)).open()
output = gateway_session.get_cmd_output(CMD.format('jumpssh'))
print("Out: {}".format(output))

I modified session.py and commented out the get_pty() line at

channel.get_pty()

Once I did this the test script above started working, and the background process successfully created the log file:

-rw-rw-r-- 1 bhoover bhoover     29 Jan 13 12:19 paramiko.log
-rw-rw-r-- 1 bhoover bhoover     29 Jan 13 12:19 jumpssh.log

Any idea why this doesn't work with get_pty() included? The Paramiko docs look like they discourage its use when running a single command with exec_command, but I'm assuming it was included here for a reason.

@wherka-ama
Copy link

@bradhvr thank you for reporting this behaviour!
We'll verify it on our side and will keep you posted in regards to a possible fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants