python 读取自定义时间内的文件(将时间作为维度的滑窗读取)

import sys
import time
import pexpect
import paramiko    
        

        # 前一天的日期
        # self.start_time = (datetime.datetime.now() + datetime.timedelta(days=-1)).strftime('%Y-%m-%d 00:00')
        self.start_time = (datetime.datetime.now() + datetime.timedelta(minutes=-18)).strftime('%Y-%m-%d %H:%M')
        # 8分钟前的文件
        self.end_time = (datetime.datetime.now() + datetime.timedelta(minutes=-8)).strftime('%Y-%m-%d %H:%M')

    """获取文件列表"""
    def get_file_list(self):
        ssh = paramiko.SSHClient()
        key = paramiko.AutoAddPolicy()
        ssh.set_missing_host_key_policy(key)
        ssh.connect(self.ip, self.port, self.user, self.password, timeout=5)
        command_line = "source /etc/profile; find %s  -type f \( -newermt '%s' -a -not -newermt '%s' \) " % (self.dns_path, self.start_time, self.end_time)
        self.log.info(command_line)
        stdin1, stdout1, stderr1 = ssh.exec_command(command_line)
        files_list = stdout1.readlines()
        return files_list

 

通过python 进行Linux服务器之间的 远程copy

    """文件传输"""
    def file_transfer(self, filename):
        passwd_key = '.*assword.*'
        cmdline = 'scp  -P  %s %s@%s:/data/10.0.0.59/dns_data/%s  %s ' % (
            self.port, self.user, self.ip, filename, self.target_path)
        self.log.info(cmdline)
        try:
            child = pexpect.spawn(cmdline)
            child.expect(passwd_key)
            child.sendline(self.password)
            child.expect(pexpect.EOF)
            self.log.info("Transfer Work Finished!")
        except Exception as e:
            self.log.error("UPLOAD FAILED!")
            self.log.error(e)

 

你可能感兴趣的:(个人日记)