这个问题与另一个问题有关:How to use sockets to send user and password to a devboard using ssh
为了执行脚本,我想连接到开发板。我想要发送给Elasticsearch机器的脚本的所有输出。
我可以使用我的笔记本电脑连接到开发板(见下图),它恰好安装了Elasticsearch。但是,当我想向开发板发送数据时,脚本没有显示任何内容。我所做的是:
找到mendel@undefined-eft:~$后立即发送命令:cd coral/tflite/python/examples/classification/Auto_benchmark\n
我做错了什么?
import paramiko
import os
#Server's data
IP = '172.16.2.47'
PORT = 22
USER = 'mendel'
PASSWORD = 'mendel'
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname = IP, port=PORT, username = USER, password = PASSWORD)
channel = ssh.invoke_shell() #to get a dedicated channel
channel_data = str()
host = str()
while True:
if channel.recv_ready(): #is there data to be read?
channel_data += channel.recv(9999).decode("utf-8")
os.system('clear')
print(channel_data)
#ONLY WORKS UNTIL HERE!!!
else:
continue
if channel_data.endswith('mendel@undefined-eft:~$'):
channel.send('cd coral/tflite/python/examples/classification/Auto_benchmark\n')
channel_data += channel.recv(9999).decode("utf-8")
print(channel_data)图像

编辑
channel = ssh.invoke_shell() #to get a dedicated channel
channel_data = str()
host = str()
while True:
if channel.recv_ready(): #is there data to be read?
channel_data += channel.recv(9999).decode("utf-8")
os.system('clear')
print(channel_data)
else:
continue
if channel_data.endswith('mendel@undefined-eft:~$ '):#it is good to send commands
channel.send('cd coral/tflite/python/examples/classification/Auto_benchmark\n')
#channel_data += channel.recv(9999).decode("utf-8")
#print(channel_data)
elif channel_data.endswith('mendel@undefined-eft:~/coral/tflite/python/examples/classification/Auto_benchmark$ '):
channel.send('ls -l\n') #python3 auto_benchmark.py')
channel_data += channel.recv(9999).decode("utf-8")
print(channel_data)

发布于 2020-06-17 06:12:22
我想你得改变一下
if channel_data.endswith('mendel@undefined-eft:~$'):至
if channel_data.endswith('mendel@undefined-eft:~$ '):根据您的提示。请注意:~$后面的空格
https://stackoverflow.com/questions/62419187
复制相似问题