2014-11-01 2 views
1

paramiko (python)에 도움이 필요합니다. 나는 비표준 SSH 인터페이스를 가진 서버를 가지고 있기 때문에 대화식 모드를 사용했고 동일한 채널에서 몇 개의 명령을 실행하고있다 (exec_command는 나를 위해 작동하지 않는다). 모든 것은 괜찮지 만 데이터가 수신되지 않을 때 응용 프로그램이 while 루프에 있기 때문에 명령 당 시간 초과를 소개하고자합니다. Channel.settimeout은 첫 번째 명령 이후에 응용 프로그램 시간 초과로 제대로 작동하지 않는 것 같습니다. 스레딩 때문에 신호를 사용할 수 없습니다. 데이터 변수가 비어있는 후 시간을 계산하기 위해 time()을 사용했을 때 전체 코드 실행이 중지되고 채널 데이터를 기다리는 것으로 나타났습니다. 모든 문제를 해결하는 방법에 대한 조언은 높이 평가 될 것입니다.python paramiko 명령에 대한 시간 초과

ssh=paramiko.SSHClient() 
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 
    try: 
     connect = ssh.connect(host,username=,password=,timeout=20) 
     file=open("test.txt","w+") 
     channel = ssh.invoke_shell() 
     data = channel.recv(5000) 
     set_of_commands = ["cmd\n","reset\n"] 

     while set_of_commands is not None: 

      file.write(data) 
      # New command might be executed here if we have 'system:' 
      if re.match("system:",data) is not None: 
       try: 
        command=set_of_commands.pop() 
        channel.send(command) 
       except: 
        break 
      data=channel.recv(5000) 
+0

제한 시간입니다. –

+0

channel.recv_exit_status()를 사용해 보셨습니까? –

답변

0

각 명령에 대해 시간 초과가 발생했을 수 있습니다. 이 게시물에서 참조를 가져 왔습니다. TCP 연결 시간에 대한 ssh.connect API에서 사용 Python Paramiko timeout with long execution, need full output

chan = ssh.get_transport().open_session() 

cmd = "timeout {0} {1}\n".format(timeouttime, cmd) 

chan.exec_command(cmd) 
+0

'timeout'+ 명령을 실행할 수있는 옵션이 없어이 기능이 작동하지 않습니다. 여기서 CoreUtils GNU를 사용하지 마십시오. – ols26

+0

나는 channel.recv_exit_status() API를 시도해야한다고 생각한다. –