python 统计当前修改html文件中的https

来源:互联网 发布:linux 执行lua脚本 编辑:程序博客网 时间:2024/05/22 10:42

需求:统计当前修改的html文件中的https 的url,通过rsysnc 推送到email服务器,转发到指定邮箱

1.python版

#! /usr/bin/env python

# -*- coding:utf-8 -*-
# Author :zyb
import os
import re
import time
file=os.popen('find /home/wwwroot/html -type f -mtime -1|grep "html$"')
with open('url-%s.txt'%(time.strftime('%Y-%m-%d')),'w') as f2:
    for html in file:
        html=html.strip()
        with open(html,'r') as f:
            f2.write("=============================================================\t\n")
            f2.write("file:%s"%html.encode('utf-8')+'\t\n')
            f2.write("-------------------------------------------------------------\t\n")
            for line in f:
                https=re.findall('(https://.*\.js|https://.*\=\d+|https://.*\.html)',line)
                if https:
                   for i in https:
                       f2.write(i+"\t\n")
    f2.write("=============================================================\t\n")
os.system('rsync -avz ./url-$(date +%F).txt rsync_backup@x.x.x.x::data  --password-file=/etc/rsync.password')

os.system('rm -rf ./url-$(date +%F).txt')


2 通过定时任务crontab 定时推送

#update today http file
50 17 * * * /usr/bin/python /server/script/update-url.py >/dev/null 2>&1


3 邮件服务器定时发邮件

脚本:

[root@n-144 data]# cat sendmail.sh
#! /bin/bash
echo "today update http files"|mail -s "$(date +%F) http file" -a /data/url-$(date +%F).txt xxxxx@qq.com xxxxx@qq.com


[root@n-144 data]# crontab -l
#today update html files
55 17 * * * /bin/sh /data/sendmail.sh >/dev/null 2>&1


结束