【问题标题】:cronjob not runnig after hours are specified?指定时间后 crontab 不运行?
【发布时间】:2021-08-14 12:49:23
【问题描述】:

嘿,我正在为我的一个项目测试 cronjobs,为此我制作了一个简单的电报机器人每分钟向我发送一条消息

代码是

import requests
from datetime import datetime
Token = "Token here"
OWNER_ID = Id here


def send():

    send_text="Message sent at : "+str(datetime.now())
    telegram_send = f"https://api.telegram.org/bot{Token}/sendmessage?chat_id={OWNER_ID}&text={send_text}"
    requests.get(telegram_send)
    print("sent at : " , datetime.now())


send()

而我的 cronjob 命令是

* * * * * /usr/bin/python3 /home/anish/cowin/tester.py >> ~/cron.log 2>&1

机器人每分钟向我发送一条消息,日志文件也记录了它

sent at :  2021-05-26 14:37:02.681277
sent at :  2021-05-26 14:38:02.444642
sent at :  2021-05-26 14:39:02.189234
sent at :  2021-05-26 14:40:01.932228
sent at :  2021-05-26 14:41:02.695751

这就是我在机器人中收到的预期

但是当我将 cronjob 命令更改为在下午 2 点到 6 点之间执行命令时,程序执行停止了

我输入的新命令是

* 14-18 * * *  /usr/bin/python3 /home/anish/cowin/tester.py >> ~/cron.log 2>&1

谁能帮我解决这个问题或指出我的代码中的任何错误??

【问题讨论】:

  • Cron 应该记录到某个文件,例如 /var/log/cron/var/log/messages。您看到任何错误吗?
  • 不,其他地方没有日志

标签: python cron cron-task


【解决方案1】:

我发现 cron 服务没有检测到我的系统时区的变化。

I got the issue solved by simply restarting cron services sudo /etc/init.d/cron restart

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-11
    • 2019-09-11
    • 2012-12-30
    • 2013-12-21
    相关资源
    最近更新 更多