import pexpect ip="10.0.0.134" name="root" pwd="123456" child=pexpect.spawn(‘ssh %s@%s‘ % ("root",ip) ) # #child.expect(‘Are.*‘) 第一次运行的时候要加上这条,会有提示,后续就没有了,这个要注意 #child.sendline(‘yes‘) child.expect (‘password:‘) child.sendline(pwd) child.expect(‘$‘) child.sendline(‘df -h‘) child.sendline("exit") child.interact() child.close()
原文:https://www.cnblogs.com/xiaomai-rhce/p/11585207.html