服务器
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()
交换机
import pexpect ip="10.20.9.61" name="ydt961" pwd="123qweasd" child=pexpect.spawn('ssh %s@%s' % (name,ip) ) # #child.expect('Are.*') #child.sendline('yes') child.expect ('ydt.*') child.sendline(pwd) child.expect('$') child.sendline('dis cu') child.sendline("exit") child.interact() child.close()
交换机
import pexpect ip="10.20.9.61" name="ydt961" pwd="123qweasd" print('正在巡检%s' %(ip)) child=pexpect.spawn('ssh %s@%s' % (name,ip) ) # #child.expect('Are.*') #child.sendline('yes') child.expect ('ydt.*') child.sendline(pwd) child.expect('$') child.sendline('dis cu') child.sendline("exit") child.interact() child.close()