【问题标题】:Ubuntu crontab not running all the timeUbuntu crontab 没有一直运行
【发布时间】:2020-06-01 14:40:51
【问题描述】:

我希望有人可以帮助我,我正在尝试使用 crontab 运行一些自动 python 脚本,并且它可以工作,但由于某种原因它不会按预期运行脚本。 如果我长时间不建立 SSH 连接,crontab 中的 python 脚本将无法运行,如果我再次登录,它们将在我注销后运行一段时间然后停止。

30 03 * * * systemctl reboot > /home/ajorge/server/python/logs/crontab_reboot.log 2>&1
45 03 * * * sudo python /home/ajorge/server/python/startup.py > /home/ajorge/server/python/logs/crontab_startup.log 2>&1
*/15 * * * * sudo python /home/ajorge/server/python/backup_auth.py > /home/ajorge/server/python/logs/crontab_auth.log 2>&1
*/15 * * * * sudo python /home/ajorge/server/python/backup_characters.py > /home/ajorge/server/python/logs/crontab_characters.log 2>&1
35 03 * * * sudo python /home/ajorge/server/python/backup_world.py > /home/ajorge/server/python/logs/crontab_world.log 2>&1
*/15 * * * * sudo python /home/ajorge/server/python/backup_clean.py > /home/ajorge/server/python/logs/crontab_clean.log 2>&1

对于下面的示例,脚本假设每 15 分钟运行一次,但我们可以看到它没有运行,并且存在间隙

如果我与服务器建立 SSH 连接,它将再次开始运行脚本,而无需我做任何事情。

谁能帮帮我?

【问题讨论】:

    标签: ubuntu cron


    【解决方案1】:

    以用户“root”的身份生成您的 crontab,然后将它们更改为:

    30 03 * * * systemctl reboot > /home/ajorge/server/python/logs/crontab_reboot.log 2>&1
    45 03 * * * python /home/ajorge/server/python/startup.py > /home/ajorge/server/python/logs/crontab_startup.log 2>&1
    */15 * * * * python /home/ajorge/server/python/backup_auth.py > /home/ajorge/server/python/logs/crontab_auth.log 2>&1
    */15 * * * * python /home/ajorge/server/python/backup_characters.py > /home/ajorge/server/python/logs/crontab_characters.log 2>&1
    35 03 * * * python /home/ajorge/server/python/backup_world.py > /home/ajorge/server/python/logs/crontab_world.log 2>&1
    */15 * * * * python /home/ajorge/server/python/backup_clean.py > /home/ajorge/server/python/logs/crontab_clean.log 2>&1
    

    【讨论】:

    • 哦,我没有用 root 编辑 crontab,让我试试,明天我会告诉你的 :) 每次更改我都会延迟检查它是否有效 :(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-06
    • 1970-01-01
    • 2014-12-03
    • 1970-01-01
    • 2019-12-14
    • 2013-12-20
    • 2014-12-02
    相关资源
    最近更新 更多