2016-10-28 7 views
0

私は自分のコード内でこの機能を持っているPythonスクリプト出力しないSSHコマンドが正しく

tenants = [ ['Kyle'], 
      ['Greg'], 
      ['Giles'], 
      ['George'], 
      ['Sebastien'], 
      ['Ricardo'], 
      ['Rocky'], 
      ['Cartman'], 
      ['Kenny'], 
      ['Bobby'], 
      ['Tim'], 
      ['Chris'] ] 

このコードを実行しています、私は名前の関数を呼び出すときに私が得る出力がある -

Connecting to server. 
<bound method ChannelFile.read of <paramiko.ChannelFile from <paramiko.Channel 1 (open) window=2097152 -> <paramiko.Transport at 0x941290L (cipher aes128-ctr, 128 bits) (active; 1 open channel(s))>>>> 
<bound method ChannelFile.read of <paramiko.ChannelFile from <paramiko.Channel 2 (open) window=2097152 -> <paramiko.Transport at 0x941290L (cipher aes128-ctr, 128 bits) (active; 1 open channel(s))>>>> 
<bound method ChannelFile.read of <paramiko.ChannelFile from <paramiko.Channel 3 (open) window=2097152 -> <paramiko.Transport at 0x941290L (cipher aes128-ctr, 128 bits) (active; 1 open channel(s))>>>> 

私はprint文を作る場合print stdout.read()、私は空白行の番号を取得します。

このコマンドをbashで実行したときの出力は、私が実際に実行しているコマンドが有効で、適切な出力を返すように出力します。

正しい文字列を表示するにはどうすればよいですか? bashコマンドの出力をstdoutからどのように得ることができますか?

ありがとうございました。

+2

コマンド全体を3重引用符で囲んでいるため、中央の 'join(item)'は実行されていません。シェルコマンドの一部です。 – Barmar

+0

コマンドの先頭に 'echo'を追加し、戻ってくるものを確認してください。 – tdelaney

+0

「正しい」文字列とは何ですか? 「期待される」出力とは何ですか?私たちは知る方法がありません。 – kindall

答えて

-1
command = client.exec_command("""sudo -u apache grep -i "my_text" /var/www/html/wwwroot/names." + ''.join(item) + "website/myfile.txt | awk -F "'" '{ print $4}'""") 

for c in command: 
    print c 

実際の結果が表示されます。基本的に応答をループします。

関連する問題