python - 为什么 cron 作业不编译 python 文件?

标签 python linux ubuntu cron

Cron 不编译我的 .py 文件,我无法从 Cron 收到电子邮件以了解 Cron 为何不起作用。但是如果我只运行命令 ~/t/test.sh在终端一切正常。

cron中的代码:

SHELL=/bin/bash
MAILTO=mymail@gmail.com
30 0-23 1-31 1-12 0-6 ~/t/test.sh


我想运行一个脚本test.sh其中有代码:
#!/bin/bash
cd /home/alex/t && python3.8 ./test.py

test.py 中的代码:
from datetime import datetime
current_time = datetime.now()
f = open("text.txt", 'w+')
f.write("Hello world! Now is {0}\n".format(current_time))
f.close()

我通过 sudo crontab-e 启动了 Cron和 crontab-e命令。我把 Cron 放在第一行 MAILTO=mymail@gmail.com .
我安装了yum install mailx .我尝试添加命令 >/dev/null 2>&1到 Cron,即写作* * * * * ~/t/test.sh >/dev/null 2>&1没有什么帮助
我使用 Ubuntu 18.04
Python3.8.2
这是 grep CRON /var/log/syslog 的日志命令显示:
Apr 30 15:35:01 av CRON[2130]: (alex) CMD (~/t/test.sh)Apr 30 15:35:01 av CRON[2129]: (alex) MAIL (mailer 68 bytes of output put get status 0x004b from MTA#012)
有没有人遇到过这个问题?
你能帮我吗?

最佳答案

你的 test.sh 应该是这样的:(需要完整路径)

#!/bin/bash
/"location where python is installed"/python/bin/python /home/alex/t/test.py

关于python - 为什么 cron 作业不编译 python 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61525690/

相关文章:

linux - Iptables 错误阻止 Pod 在 Kubernetes 中启动

ruby-on-rails - 在 Ubuntu VPS 上单独运行 RoR

php - Ubuntu 亚马逊网络服务 LAMP 堆栈设置

python - 是否可以更改 firestore 中的文档 ID?

python - 如何在python中从txt中选择不同的列

Java FX 应用程序无法在带有 Linux 的浏览器上运行

node.js - 我无法让 Electron 在 Electron 中运行以在 WSL2 Ubuntu 20.04 中运行

java - MQ Client 与 Python 一起使用,无需安装

python - 将字节写入波形文件?

c++ -/usr/bin/ld : cannot find -lcaffe