*交互式示例:
===第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