栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

linux 定时调用.sh文件

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

linux 定时调用.sh文件

用来计算2个时间的时间差。 调用的时间建议采用挂载的方式,即: nohup python -u xxx.py > nohup.test.log 2>&1 &
import time
import os
a = 1650380930.2743425 # 上一刻时间
'''
1. time.time()生成
2. time.mktime(time.strptime("2022-04-20 07:33:00","%Y-%m-%d %H:%M:%S")) 特定时间生成
'''
last_hours= -1
last_minutes= -1
last_seconds = -1
while True:
    b = time.time() ## 当前时间
    dist = b-a
    minutes, seconds = divmod(dist, 60)
    hours, minutes = divmod(minutes, 60)
    ### days, hours = divmod(hours, 24)
    if minutes != last_minutes: ## 为了打印看看程序是否在走
        print ('hours = ', hours, ' , minutes  = ', minutes )
        last_minutes = minutes 
    if hours > 3: ## 时间间隔达到了,运行shell 文件
        data = os.popen('./test.sh')
        print (data.read())
        break
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/828329.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号