2017-10-06 9 views
0

私はparamikoとAWSを試していますが、SSHの動作に問題があります。これは、サーバーに手動でSSH接続してもエラーメッセージが表示されない場合に機能します。私が間違っていることを理解するのに少し役立つことができますか?pythonからstdoutを取得する際の問題paramiko

私はstdout.read()とstdout.readlines()の両方を試しました。どちらも空になります。

コード:

#Load the key into a file and attempt to SSH in 
key = paramiko.RSAKey.from_private_key_file('TestInstanceKey.pem') 
ssh = paramiko.SSHClient() 
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 
print("Connecting") 
#Try to ssh in and run and display ifconfig 
try: 
    ssh.connect(hostname=instance.public_ip_address, username="ec2-user", 
    pkey=key) 
    print("Connected") 
    print("Executing ifconfig") 
    stdin, stdout, stderr = ssh.exec_command("ifconfig") 
    lines = stdout.read() 
    print(lines) 
    for line in lines: 
     print(line) 
    ssh.close() 
except Exception as e: 
    print(e) 
    input("Press enter to continue...") 

出力:私は、サーバーにSSH

Connecting 
Connected 
Executing ifconfig 
b'' 

出力:

ssh -i TestInstanceKey.pem [email protected] 

     __| __|_ ) 
     _| ( / Amazon Linux AMI 
     ___|\___|___| 

https://aws.amazon.com/amazon-linux-ami/2016.09-release-notes/ 
22 package(s) needed for security, out of 67 available 
Run "sudo yum update" to apply all updates. 
Amazon Linux version 2017.09 is available. 
[[email protected] ~]$ ifconfig 
eth0  Link encap:Ethernet HWaddr XXXXXXXXXXX 
      inet addr:XXXXXXXXX Bcast:Xxxxxxxxx.255 Mask:255.255.240.0 
      inet6 addr: xxxxxxx Scope:Link 
      UP BROADCAST RUNNING MULTICAST MTU:9001 Metric:1 
+0

stderrには何かがありますか? – Kyle

+0

b'bash:ifconfig:コマンドが見つかりません\ n ' 完全なパスが必要なようです。もう一度試してみる。 – Smipims

答えて

0

私は完全なパスを行うために必要な。/ifbin/ifconfig ifconfigだけではありません。

関連する問題