【问题标题】:Start a Python script in a shell with SSH使用 SSH 在 shell 中启动 Python 脚本
【发布时间】:2018-01-31 09:13:53
【问题描述】:

我想用paramiko 启动一个 Python 脚本,它连接到我的树莓派,充当服务器。然后在连接到覆盆子之后,它会启动一个这样的脚本(从另一台电脑向 arduino 发送数据):

import tty
import sys
import termios
import serial
import os

arduino = serial.Serial('/dev/ttyUSB0' , 9600)

x = "./mjpg_streamer -i \"./input_uvc.so -d /dev/video0 -y\" -o \"./output_http.so -w ./www\""
os.system(x)


orig_settings = termios.tcgetattr(sys.stdin)

tty.setraw(sys.stdin)
x = 0
while x != chr(27): # ESC
    x=sys.stdin.read(1)[0]
    arduino.write(x)
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, orig_settings)

这段代码可以正常工作,只是为了简化。

我想通过 ssh 自动连接到树莓派,并启动一个 python 脚本,它会要求输入 - 在上面的代码中是一个常量 -。 我想用上面已经启动的脚本打开一个新的 shell 或者类似的东西......

【问题讨论】:

    标签: python python-2.7 ssh paramiko


    【解决方案1】:

    快速回答,没有任何选项可以帮助您将密码插入 ssh 命令。您必须设置一个共享密钥对才能在没有密码提示的情况下使用 ssh。在互联网上搜索可以为您提供大量答案,例如:http://www.thegeekstuff.com/2008/11/3-steps-to-perform-ssh-login-without-password-using-ssh-keygen-ssh-copy-id

    首先,设置密钥对。然后用普通的ssh检查是否成功。最后,在你的 python 脚本中,添加一些代码来处理 ssh。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-16
      • 2012-08-02
      • 2016-08-11
      • 2010-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多