本人python小菜鸟,初学者,但刚刚学习就python产生了浓厚的兴趣,争取今后把线上的shell脚本都改成python
#!/usr/bin/env python
import paramiko
import threading
import fileinput
#d=raw_input("shuru zu:")
#mingling=raw_input("mingling:")
file1=open("/opt/duoyongtu/memcache.txt","r")
print file1
list1=[]
def ssh2(hostname,port,username,pkey,cmd):
key=paramiko.RSAKey.from_private_key_file(pkey)
s=paramiko.SSHClient()
s.load_system_host_keys()
s.connect(hostname,port,username,pkey=key)
stdin,stdout,stderr=s.exec_command(cmd)
print stdout.read()
def test2():
for c in file1.readlines():
cc=c.split(" ")
list1.append(cc)
test2()
if __name__==‘__main__‘:
for i in range(len(list1)):
print i
print list1
ip=list1[i][0]
dd=list1[i][1]
ddd=list[i][2]
print dd
print ip
cmd=‘sed -i‘+‘ \‘s/couchbase.address=192.168.0.63:8091,192.168.0.64:8091,192.168.0.101:8091,192.168.0.102:8091/couchbase.address=192.168.0.49:8091,192.168.0.50:8091,192.168.0.109:8091,192.168.1.74:8091,192.168.1.75:8091/g\‘ ‘+list1[i][1]+‘/htdocs/WEB-INF/lover-web.conf‘
print cmd
cmd2=‘/usr/local/resin/bin/resin.sh ‘+‘restart ‘+‘-server ‘+list1[i][2]
port=22
username=‘root‘
pkey=‘/root/.ssh/id_rsa‘
threads=[]
a=threading.Thread(target=ssh2,args=(ip,port,username,pkey,cmd))
a.start()
本文出自 “expect批量同步数据” 博客,请务必保留此出处http://4249964.blog.51cto.com/4239964/1364361