【问题标题】:use SSH over Python通过 Python 使用 SSH
【发布时间】:2013-03-22 15:26:13
【问题描述】:

如何在 python 脚本上运行这个 SSH?

ssh gateway@192.168.0.189 'DISPLAY=:0 notify-send "Title" "Description"'

我的 python 脚本将要求 Title 的 raw_input() 和 Description 的另一个。然后python将运行SSH插入用户输入的TitleDescription

【问题讨论】:

标签: python ubuntu ssh openssh


【解决方案1】:
import subprocess
subprocess.check_call(
    '''ssh gateway@192.168.0.189 'DISPLAY=:0 notify-send "{0}" "{1}"' '''.format(title, description),
    shell=True)

【讨论】:

  • 如果输入来自用户,请不要忘记正确转义:)
  • 如何正确转义输入?我的意思是它在使用撇号时不断出错。
【解决方案2】:

如果您想要更多的控制,您还应该查看 paramiko 库:https://github.com/paramiko/paramiko 这是一个用于 python 的 SSH2 库。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-13
    • 2011-12-25
    • 1970-01-01
    • 2018-04-14
    • 2018-04-05
    • 1970-01-01
    • 2018-06-04
    相关资源
    最近更新 更多