Skip to content

Can't execute background process on remote server #235

@bradhvr

Description

@bradhvr
  • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions