Posted By

wearetherock on 09/29/09


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

bubnoff


Pexpect Example


 / Published in: Python
 

  1. import pexpect
  2. password = open("config/qlive.auth", "r").readline().strip()
  3. p = pexpect.spawn("sudo bash install_dynamicctrl.sh")
  4. i = p.expect([".ssword:*", pexpect.EOF])
  5. p.sendline(password)

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: preslib on August 29, 2010

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 [email protected] 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

You need to login to post a comment.