目前写这个的目的是为了实现,可以批处理发送的一个模块; 后期将各个模块整合到一起,实现更加丰富的功能;
需要在脚本目录下新建一个ip.txt 文件,里面为脚本需要执行的ip地址;
并且执行主机需要与目标机器建立秘钥匹配,毕竟密码直接放服务器上是一种不安全的行为;
批量建立秘钥是有脚本的sshpass做的,改天上传;
使用方法 ./send 源文件 目标地址
源码如下:
#!/usr/bin/python
# -*- coding:utf-8 -*-
import threading
import time
import sys
import os
class myThread (threading.Thread):
def __init__(self, threadID, name, source_file, target_dir):
threading.Thread.__init__(self)
self.threadID = threadID
self.name = name
self.source_file = source_file
self.target_dir = target_dir
def run(self):
this_str="start :" + self.name
print (this_str)
try :
os.system(('scp -o ConnectTimeout=5 -q -r %s root@%s:%s') % (str(self.source_file), str(self.name), str(self.target_dir)))
except :
print ('