[問題] 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