python paramiko远程执行命令打开窗口_Paramiko:从远程执行命令的标准输出读取

*交互式示例:

===第1部分,这显示服务器中的sh输出,在结尾处是“>”

需要一些输入才能继续或退出

selilsosx045:uecontrol-CXC_173_6456-R32A01 lteue$/uecontrol.sh-主机本地主机

UE控件:使用以下命令启动UE控件:

UE控件:java-Dlogdir=-Duecontrol.configdir=./etc-jar./server/server-R32A01.jar-host本地主机

从文件/Users/lteue/Downloads/uecontrol-CXC_173_6456-R32A01/etc/uecontrol.properties加载属性

向主机localhost启动远程CLI

输入命令Q退出CLI或命令帮助

获取有关可用命令的信息。

CLI已准备好输入。

uec>

===带peramiko的Pyhton代码===*

尝试以下方法:而不是stdout.channel.exit_status_ready():def shCommand(server_list):

server_IP = server_list[0]

username = server_list[1]

password = server_list[2]

ssh = paramiko.SSHClient()

ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

ssh.connect(server_IP,22,username, password)strong text

commandList = ['list \n']

alldata = getUeInfo(ssh,commandList)

ssh.close()

def getUeInfo(ssh,commandList):

data_buffer = ""

num_of_input = 0

stdin, stdout, stderr = ssh.exec_command('cmd')

while not stdout.channel.exit_status_ready():

solo_line = ""

if stdout.channel.recv_ready():

solo_line = stdout.channel.recv(1024) # Retrieve the first 1024 bytes

data_buffer += solo_line

if(cmp(solo_line,'uec> ') ==0 ): #len of solo should be 5 ,

if num_of_input == 0 :

data_buffer = ""

for cmd in commandList :

#print cmd

stdin.channel.send(cmd)

num_of_input += 1

if num_of_input == 1 :

stdin.channel.send('q \n')

num_of_input += 1

return data_buffer

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值