私はpxsshを使って簡単なsshログインに取り組んでいます。 T.J.クックブックのConnorスクリプトpxsshで立ち往生しました。最初のログインに成功した後、再度ログインしませんか?
Pythonインタプリタから試してみると、pxsshを使ってリモートマシンに正常に入り、コマンドを渡すことができました。 以下はその見方です。
>>> from pexpect import pxssh
>>> s = pxssh.pxssh()
>>> s.login("192.168.1.107", "shineesh", "password123")
True
>>> s
<pexpect.pxssh.pxssh object at 0xb72d772c>
>>> s.sendline("ifconfig")
9
>>> s.prompt()
True
>>> print s.before
ifconfig
eth0 Link encap:Ethernet HWaddr 3X:XX:XX:XX:XX:X4
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
今、私は再び同じことをしようとしたとき、私はこの
>>> s = pxssh.pxssh()
>>> s.login("192.168.1.107", "shineesh", "password123")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/pexpect/pxssh.py", line 331, in login
if not self.sync_original_prompt(sync_multiplier):
File "/usr/lib/python2.7/dist-packages/pexpect/pxssh.py", line 218, in sync_original_prompt
b = self.try_read_prompt(sync_multiplier)
File "/usr/lib/python2.7/dist-packages/pexpect/pxssh.py", line 182, in try_read_prompt
prompt += self.read_nonblocking(size=1, timeout=timeout)
File "/usr/lib/python2.7/dist-packages/pexpect/pty_spawn.py", line 455, in read_nonblocking
return super(spawn, self).read_nonblocking(size)
File "/usr/lib/python2.7/dist-packages/pexpect/spawnbase.py", line 149, in read_nonblocking
raise EOF('End Of File (EOF). Exception style platform.')
pexpect.exceptions.EOF: End Of File (EOF). Exception style platform.
>>>
を取得し、以下のスクリプトは、EOFのexeception
#! /usr/bin/python -tt
from pexpect import pxssh
import pexpect
def send_commands(s, command):
s.sendline(command)
s.prompt(pexpect.EOF)
print s.before
def connect(host, username, password):
try:
child = pxssh.pxssh()
child.login(host, username, password)
return child
except Exception, e:
print "[-] Error Connecting\n" + str(e)
exit(0)
def main():
s = connect('192.168.1.107', 'shineesh', 'password123')
send_commands(s, 'ifconfig')
if __name__ == '__main__':
main()
-----出力をスローBelow-- ------------
[-] Error Connecting
End Of File (EOF). Exception style platform.
は再び
http://stackoverflow.com/questions/24919980/pxssh-throwing-end-of-file-eof-exception-style-platform-exception
http://pexpect.sourceforge.net/doc/
----------新しいスクリプトからいくつかのスレッド/参照--------------
#! /usr/bin/python -tt
from pexpect import pxssh
import pexpect
def send_commands(s, command):
s.sendline(command)
s.prompt(pexpect.EOF)
print s.before
def connect(host, username, password):
try:
child = pxssh.pxssh()
child.login(host, username, password)
child.expect(pexpect.EOF, timeout=None)
return child
except Exception, e:
print "[-] Error Connecting\n" + str(e)
exit(0)
def main():
s = connect('192.168.1.107', 'shineesh', 'password123')
send_commands(s, 'ls -all')
if __name__ == '__main__':
main()
を追いました
-------出力-------------
[-] Error Connecting
End Of File (EOF). Exception style platform.
私はここで間違っているんですか?