自动12个小时执行同步语雀

python代码

#__author__ = 'chenghoufeng'
# -*- coding: utf-8 -*-

import time
import sys
import os

def print_ts(message):
    print "[%s] %s"%(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), message)

def run(interval):
    print_ts("-"*61)
    print_ts(u"每 %s 秒执行一次."%interval)
    print_ts("-"*61)
    while True:
        try:
            # sleep for the remaining seconds of interval
            time_remaining = interval-time.time()%interval
            print_ts(u"开始执行时间: %s (%s 秒)..."%((time.ctime(time.time()+time_remaining)), time_remaining))
            time.sleep(time_remaining)
            print_ts("开始运行。")
            print_ts("-"*61)
            os.system("yuque-hexo clean >> yuque-hexo.log")
            print u'延迟10秒执行'
            time.sleep(10)
            sync  = os.system("yuque-hexo sync  >> yuque-hexo.log")
        except Exception, e:
            print e

if __name__ == '__main__':
    # 收集,统计bug数据
    reload(sys)
    sys.setdefaultencoding('utf-8')
    # 每15分钟(1800秒)收集一次Bugs数据,并进行统计。
    interval = 43200
    run(interval)

sh

#!/bin/bash
echo "开始运行hexo"
rm *hexo.log
nohup hexo server >> hexo.log 2>&1 &
echo "开始执行定时"
nohup python -u yuque-hexo.py >> hexo.log 2>&1 &
echo "运行结束"



知识共享许可协议本作品采用知识共享署名-相同方式共享 4.0 国际许可协议进行许可。

相关推荐

【教程】卸载1Panel

1、卸载1Panel命令行 ✅只要在Linux终端输入1pctl uninstall就能卸载掉1panel。 💥上面的卸载命令行,百度和官网找都找 ...

暂无评论

目录展开