ubuntu - Ubuntu crontab 没有一直运行
问题描述
我希望有人可以帮助我,我正在尝试使用 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 连接,它将再次开始运行脚本,而无需我做任何事情。
任何人都可以帮助我吗?
解决方案
将您的 crontab 生成为用户“root”,然后将它们更改为:
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
推荐阅读
- javascript - 在保持子顺序的同时对主行进行排序 - jquery
- javascript - 显示 2 张幻灯片时,光滑的轮播自适应高度不起作用
- javascript - eventListener 函数中的递归 setTimeout(鼓音序器)
- java - 关于在 java 中使用构造函数和方法以及构造函数为什么不起作用的简单问题
- html - 我使用的功能有什么问题
- flutter - 使用 Flutter 构建特定的导航动画
- javascript - Javascript按钮在页面加载时运行一次点击事件本身并且在点击时不起作用
- c# - Binding a RadCombobox inside a radgrid
- html - 进度条中的动画背景 (HTML5) Shadow DOM
- python - 初始化脚本在 databricks 笔记本中运行良好,但在附加到集群时失败