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

xiaoxiao2021-02-28  167

需求:统计当前修改的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

结束

转载请注明原文地址: https://www.6miu.com/read-21276.html

最新回复(0)