重定向输出的Python脚本崩溃,输出中没有错误

时间:2018-11-07 17:46:32

标签: python bash cron

我有一个在Ubuntu服务器上运行@reboot的python脚本。该脚本的输出将重定向到日志文件。整个cronjob看起来像这样:

@reboot stdbuf -oL python /home/justin/script.py 2> /home/justin/log

“ stdbuf”将停止缓冲输出,直到脚本完成为止,而是立即将其写出到日志文件中。

该脚本包含一个无限循环,因此仅应在崩溃时停止。但是,当我检查生成的日志文件时,在文件末尾没有看到错误消息。

这里是否缺少我想要的东西,或者将所有python错误重定向到文件的更好方法?

1 个答案:

答案 0 :(得分:0)

如果这样设置会更好吗?

@reboot /path/to/stdbuf -oL /path/to/python /home/justin/script.py 2> /home/justin/log
相关问题