Python, Paramiko: How to do a “ssh -n user@host cmd” using paramiko?

后端 未结 2 1434
感情败类
感情败类 2021-01-15 14:54

I\'m trying to execute a command remotely via SSH from Python, and in this particular case need stdin to be redirected to /dev/null.

That is, the same as us

相关标签:
2条回答
  • 2021-01-15 15:09

    I would ditch paramiko and start using fabric. It will let you do remote calls on the system. It uses paramiko for the ssh connection and provides the nice clean interface for doing alot more.

    I am not sure why you need to pip stdin to /dev/null but there are settings to suppress it with fabric.

    Goodluck!

    0 讨论(0)
  • 2021-01-15 15:22

    Unless I understand your question incorrectly: you don't need to achieve this. Nothing is automatically read from stdin/written to the remote process' stdin unless you yourself explicitly do so. So you don't need to prevent reading from stdin from happening?

    EDIT: there might be an issue if the remote process expects data on stdin, and keeps waiting for it? Try calling shutdown_write() on the channel:

    stdin, stdout, stderr = client.exec_command(cmd)
    stdin.channel.shutdown_write()
    
    0 讨论(0)
提交回复
热议问题