2016-07-04 7 views
0

지난 주의 내 question에 대한 "후속 조치"입니다. 기본적으로 pexpect 을 사용하는 ssh-copy-id가 때때로이 멈추는 비단뱀 코드가 있습니다.때때로 ssh-copy-id가 걸려 있습니다.

필자는 이것이 pexect 문제 일 수 있다고 생각했지만 더 이상 그 같은 걸림에서 "stacktrace"를 수집 할 수있게 된 것은 아닙니다. 여기에서 내 응용 프로그램의 일부 흔적을 볼 수 있습니다. 제한 시간에 실행 한 후 스택 추적 다음 :

2016-07-01 13:23:32 DEBUG   copy command: ssh-copy-id -i /yyy/.ssh/id_rsa.pub [email protected] 
2016-07-01 13:23:33 DEBUG   first expect: 1 
2016-07-01 13:23:33 DEBUG   sending PASSW0RD 
2016-07-01 13:23:33 DEBUG   consuming output from remote side ... 
2016-07-01 13:24:03 INFO   Timeout occured ... stack trace information ... 

2016-07-01 13:24:03 INFO   Traceback (most recent call last): 


File "/usr/local/lib/python3.5/site-packages/pexpect-3.3-py3.5.egg/pexpect/__init__.py", line 1535, in expect_loop 
c = self.read_nonblocking(self.maxread, timeout) 
File "/usr/local/lib/python3.5/site-packages/pexpect-3.3-py3.5.egg/pexpect/__init__.py", line 968, in read_nonblocking 
raise TIMEOUT('Timeout exceeded.') 
pexpect.TIMEOUT: Timeout exceeded. 

During handling of the above exception, another exception occurred: 
Traceback (most recent call last): 
File "xxx/PrepareSsh.py", line 28, in execute 
    self.copy_keys(context, user, timeout) 
File "xxx/PrepareSsh.py", line 83, in copy_keys 
    child.expect('[#\$]') 
File "/usr/local/lib/python3.5/site-packages/pexpect-3.3-py3.5.egg/pexpect/__init__.py", line 1451, in expect 
timeout, searchwindowsize) 
File "/usr/local/lib/python3.5/site-packages/pexpect-3.3-py3.5.egg/pexpect/__init__.py", line 1466, in expect_list 
timeout, searchwindowsize) 
File "/usr/local/lib/python3.5/site-packages/pexpect-3.3-py3.5.egg/pexpect/__init__.py", line 1568, in expect_loop 
raise TIMEOUT(str(err) + '\n' + str(self)) 
pexpect.TIMEOUT: Timeout exceeded. 
<pexpect.spawn object at 0x2b74694995c0> 
version: 3.3 
command: /usr/bin/ssh-copy-id 
args: ['/usr/bin/ssh-copy-id', '-i', '/yyy/.ssh/id_rsa.pub', '[email protected]p'] 
searcher: <pexpect.searcher_re object at 0x2b746ae1c748> 
buffer (last 100 chars): b'\r\n/usr/bin/xauth: creating new authorityy file /home/hmcmanager/.Xauthority\r\n' 
before (last 100 chars): b'\r\n/usr/bin/xauth: creating new authority file /home/hmcmanager/.Xauthority\r\n' 
after: <class 'pexpect.TIMEOUT'> 

그래서, 내가 좀 이상한 것을 발견 : xauth를 수신 pexpect 메시지에 표시.

오늘은 테스트 용으로 다른 VM을 만들었습니다. 모든 설정을 수동으로 수행했습니다. 그래서

> ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected] 

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/xxx/.ssh/id_rsa.pub" 
The authenticity of host 'some.ip (some.ip)' can't be established. 
ECDSA key fingerprint is SHA256:7... 
Are you sure you want to continue connecting (yes/no)? yes 
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed 
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys 
[email protected]'s password: 
Number of key(s) added: 1 
Now try logging into the machine, with: .... 

요점을 되풀이가 있습니다 : 이것은 그렇게되면 내가 볼 것입니다 내가 수동으로 ssh를 복사 - ID를 실행할 때

  • ... 모든 작품; ssh-copy-id를 프로그래밍 방식으로 실행하면 "xauth"문자열이 출력되지 않고
  • 표시됩니다. 대부분의 경우 작동합니다. 하지만 때때로 타임 아웃이 있습니다 ... xauth에 대한 메시지가 내 클라이언트에게 전송됩니다.

이것은 나를 미치게합니다. 어떤 아이디어라도 환영합니다.

+0

다음 명령 프롬프트를 기대하고 있습니다 :'child.expect ('[# \ $]')'. 그러나 당신의 수동 출력물에서 프롬프트는'>'처럼 보입니다. – Samuel

+0

제가 사용할 수있는 정규 표현식에 들어가려고합니다. 가능한 한 많이 일치하는 것을 제공 할 수 있습니까? EOF까지 모든 것을 정말로 "소비"합니까? 그리고 나는 당신이하는 말을 잘 모릅니다 : ">"그것은 내 클라이언트 시스템의 프롬프트입니다. 이것이 pexect가 원격 시스템에서 돌아 오는 입력에 반응하는 데 사용하는 패턴과 어떤 관련이 있습니까? – GhostCat

+0

이 child.expect 시도 ('[#> :]') – Samuel

답변

1

xauth X11 전달을 요청하는 것처럼 냄새가납니다. ~/.ssh/config에 구성됩니다. 이는 구성을 중단시킬 수있는 구성의 차이 일 수 있습니다.