[問題] paramiko multi command

看板Python作者 (鳳山下智久)時間3年前 (2020/06/01 23:51), 編輯推噓0(001)
留言1則, 1人參與, 3年前最新討論串1/1
各位大大,小弟目前在寫一個要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出來, 有請大大幫我解答了,感謝 -- 有一次記者問洋基傳奇球星狄馬喬(Joseph Paul DiMaggio)︰ 「Mr. DiMaggio,你在大聯盟打了無數場比賽,為什麼每一場比賽都還要像菜鳥一般拚命 呢?」狄馬喬這樣回答︰「因為我知道每一場比賽數萬名觀眾裡頭,一定會有哪個小孩是 第一次來看我打球。」 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 59.124.115.148 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1591026717.A.591.html

06/02 10:12, 3年前 , 1F
推簽名檔
06/02 10:12, 1F
文章代碼(AID): #1UrIGTMH (Python)
文章代碼(AID): #1UrIGTMH (Python)