/ Published in: Python
Expand |
Embed | Plain Text
import pexpect password = open("config/qlive.auth", "r").readline().strip() p = pexpect.spawn("sudo bash install_dynamicctrl.sh") i = p.expect([".ssword:*", pexpect.EOF]) p.sendline(password)
Comments
Subscribe to comments
You need to login to post a comment.

How can I use 'pexpect' to run a script in a remote machine? Please help to modify following code to achieve my goal.
!/usr/bin/env python
import pexpect
ssh_newkey = 'Are you sure you want to continue connecting'
my ssh command line
p=pexpect.spawn('ssh user@192.168.0.1 uname -a')
i=p.expect([sshnewkey,'password:',pexpect.EOF]) if i==0: print "I say yes" p.sendline('yes') i=p.expect([sshnewkey,'password:',pexpect.EOF]) if i==1: print "I give password", p.sendline("mypassword") p.expect(pexpect.EOF) elif i==2: print "I either got key or connection timeout" pass print p.before # print out the result