を使用してサーバーに接続しており、順次出力を受信するためparamiko
に使用しようとしています。channel.send
以下のスクリプトは、 からの出力をキャッチできませんchannel.recv
。何か案は?
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect("xx.xx.xx.xx",username='kshk',password='xxxxxxxx',key_filename='/home/krisdigitx/.ssh/id_rsa')
channel = ssh.invoke_shell()
channel.send('df -h\n')
while channel.recv_ready():
outp = channel.recv(1024)
print outp
与えます:
krisdigitx@krisdigitx-Dell-System-XPS-L702X:~/SCRIPTS$ python test.py
Traceback (most recent call last):
File "test.py", line 11, in <module>
print outp
NameError: name 'outp' is not defined
インタープリターモードでスクリプトを実行すると機能します...
>>> import paramiko
>>> ssh = paramiko.SSHClient()
>>> ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
>>> ssh.connect("xx.xx.xx.xx",username='kshk',password='xxxxx',key_filename='/home/krisdigitx/.ssh/id_rsa')
>>> channel = ssh.invoke_shell()
>>> channel.send('df -h\n')
6
>>> while channel.recv_ready():
... outp = channel.recv(1024)
...
>>> print outp
/dec/sda
7.2T 6.6T 622G 92% /tmp/xxx
[kshk@server ~]$
>>>