服務器服務器
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()
交換機ssh
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()
交換機spa
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()