#!/usr/bin/env python
import pexpect
ssh_newkey = 'Are you sure you want to continue connecting'
# my ssh command line
p=pexpect.spawn('ssh [email protected] uname -a')
i=p.expect([ssh_newkey,'Password:',pexpect.EOF])
if i==0:
print "I say yes"
p.sendline('yes')
i=p.expect([ssh_newkey,'password:',pexpect.EOF])
if i==1:
print "I give password",
p.sendline(admin123)
p.expect(pexpect.EOF)
elif i==2:
print "I either got key or connection timeout"
pass
print p.before # print out the result
Error:
python test/ssh3.py
File "test/ssh3.py", line 15
p.sendline(admin123)
^
SyntaxError: invalid syntax
You have mail in /var/spool/mail/root