#!/usr/bin/env python
import paramiko
import threading
import fileinput
d=raw_input("shuru zu:")
mingling=raw_input("mingling:")
f="/opt/duoyongtu/"+d+".txt"
file1=open(f,"r")
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():
list1.append(c)
test2()
ip=‘\n‘.join(list1)
print ip
if __name__==‘__main__‘:
cmd=mingling
test2()
print list1
hostname=list1
port=22
username=‘root‘
pkey=‘/root/.ssh/id_rsa‘
threads=[]
for i in hostname:
line = i.rstrip()
a=threading.Thread(target=ssh2,args=(line,port,username,pkey,cmd))
a.start()
本文出自 “expect批量同步数据” 博客,转载请与作者联系!