2016-07-04 25 views
0

これは先週から私のquestionの「フォローアップ」です。基本的に私は、pexpect を使ってssh-copy-idが時折がハングするいくつかのpythonコードが表示されているのを見ています。時々ぶら下がっている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]'] 
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に設定されます。これは、ハングを引き起こす可能性のある設定の違いかもしれません。

関連する問題