I'm trying to do a Python script (with a loop) to connect in SSH,it works if everything is good ( password and route) but stop when it's not working(wrong password or no routes to host ).Here is the important part of the script, how can I control if everything is working ?
connexion = pexpect.spawn("ssh -o StrictHostKeyChecking=no "+user+"@" + ip )
index=connexion.expect(':')
connexion.sendline(password + "\r")
connexion.expect('>')
connexion.sendline('show clock \r')
connexion.expect('>')
connexion.sendline('exit')
connexion.close()
I get the error :
Traceback (most recent call last):
File "script.py", line 21, in <module>
connexion.expect('>')
File "/usr/lib/python2.7/dist-packages/pexpect/__init__.py", line 1418, in expect
timeout, searchwindowsize)
File "/usr/lib/python2.7/dist-packages/pexpect/__init__.py", line 1433, in expect_list
timeout, searchwindowsize)
File "/usr/lib/python2.7/dist-packages/pexpect/__init__.py", line 1521, in expect_loop
raise EOF(str(err) + '\n' + str(self))
pexpect.EOF: End Of File (EOF). Exception style platform.
<pexpect.spawn object at 0x7fcfeecee750>
version: 3.1
command: /usr/bin/ssh
args: ['/usr/bin/ssh', '-o', 'StrictHostKeyChecking=no', 'username@10.9.128.5']
searcher: <pexpect.searcher_re object at 0x7fcfeecee850>
buffer (last 100 chars): ''
before (last 100 chars): ' connect to host 10.9.128.5 port 22: No route to host\r\r\npassword\r\n\r\n'
Thanks