【发布时间】:2020-08-14 22:50:27
【问题描述】:
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 和 crontab-e 命令启动了 Cron。我将 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)
有人遇到过这个问题吗? 你能帮忙吗?
【问题讨论】: