python3 pexpect模块

pexpect

import pexpect
ip="127.0.0.1"
name="root"
pwd="root"
#发送命令执行交互  
child=pexpect.spawn('ssh  %s@%s' % ("root",ip)  )
child.expect ('password:')
child.sendline(pwd)
child.expect('$')
child.sendline('df -h')
#发送命令  
child.sendline("exit")
child.interact()
#关闭pexpect  
child.close()

猜你喜欢

转载自www.cnblogs.com/fengzi7314/p/10218567.html
今日推荐