[问题] paramiko multi command

楼主: kennykobe (凯尼狗鼻哥)   2020-06-01 23:51:51
各位大大,小弟目前在写一个要ssh进去一台linux,然后接着下两个command
import paramiko
import time
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
key_path = '/XXX/xxxx/xxx/xxx'
key = paramiko.RSAKey.from_private_key_file(key_path)
ssh.connect(hostname=xxx.xxx.xxx.xxx, username='sysops', pkey=key)
channel = ssh.invoke_shell()
channel.send('/usr/local/bin/redis-cli')
channel.send('\n')
time.sleep(1)
resp = channel.recv(9999)
output = resp.decode('ascii').split(',')
channel.send('keys *')
channel.send('\n')
time.sleep(1)
resp = channel.recv(9999)
output = resp.decode('ascii').split(',')
print (''.join(output))
第一个command就是进入command line mode, 而第二个command就是印出所有的key
但是程式print出来的结果只有 127.0.0.1:6379> keys *, 没有把第二个command的值
print出来, 有请大大帮我解答了,感谢
作者: cuteSquirrel (松鼠)   2020-06-02 10:12:00
推签名档

Links booklink

Contact Us: admin [ a t ] ucptt.com