2016-10-28 2 views
0

나는 내 코드의 내부에이 기능이파이썬 스크립트 출력되지 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 stdout.read(), 빈 줄 번호가 나타납니다.

bash에서이 명령을 실행할 때의 출력이 원하는 출력이므로 실행중인 실제 명령이 유효하고 올바른 출력을 반환합니다.

어떻게 표시 할 올바른 문자열을 얻을 수 있습니까? stdout에서 bash 명령으로 예상되는 출력을 얻으려면 어떻게합니까?

감사합니다.

+2

전체 명령을 삼중 따옴표로 묶었으므로 가운데에있는'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 

그러면 실제 결과가 출력됩니다. 기본적으로 응답을 반복하십시오.

관련 문제