简体   繁体   English

Crontab-Python脚本运行,将输出发送到邮件,但不写入文件

[英]Crontab - Python Script Runs, sends output to mail, but doesn't write to file

I have a job that I have set to run every 5 minutes. 我有一份工作,每5分钟要执行一次。 I confirm that it indeed runs by running: 我通过运行来确认它确实可以运行:

grep CRON /var/log/syslog

It shows that it is running the exact command I need it to run 'python3 /root/foofolder/foo.py R' 它显示它正在运行确切的命令,我需要它来运行'python3 /root/foofolder/foo.py R'

Dec 29 23:05:01 fooserver CRON[9306]: (root) CMD (python3 /root/foofolder/foo.py R)

It sends the output to mail. 它将输出发送到邮件。 I read the mail and output looks as if I was running it in terminal, exactly as I need. 我阅读了邮件,并且输出看起来就像我在终端中运行它一样,完全符合我的需要。 The script is supposed to write out to a file. 该脚本应该写出到文件中。 It fails to do so. 它没有这样做。 Running the script in the command line writes the file just fine. 在命令行中运行脚本会将文件写入。 I've given the .py file +x permissions and added 我已经授予.py文件+ x权限并添加了

#!/usr/bin/python

to the beginning of the .py script. 到.py脚本的开头。 Is there anything else I am missing? 还有什么我想念的吗?

尝试在脚本的早期(打开文件之前)使用绝对路径和/或os.chdir到一个众所周知的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM