파이썬 pexpect

(Python pexpect 예제에서 넘어옴)
Python pexpect 예제

1 소스 코드[ | ]

import pexpect

ssh_newkey = 'Are you sure you want to continue connecting'
conn = 'ssh root@localhost'
passwd = '********'
p = pexpect.spawn(conn)
index = p.expect( [ssh_newkey, 'password:', pexpect.EOF, pexpect.TIMEOUT], 1 )
if index == 0:
	print 'index == 0'
	p.sendline('yes')
	index = p.expect( [ssh_newkey, 'password:', pexpect.EOF, pexpect.TIMEOUT], 1 )
if index == 1:
	print 'index == 1'
	p.sendline(passwd)
	index = p.expect( [pexpect.EOF, pexpect.TIMEOUT], 1 )
elif index == 2:
	print "Cannot connect to " + conn
	sys.exit(0)

2 같이 보기[ | ]

3 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}