crontab tee 命令不会将 stdout 写入 txt 文件,而是将其清除 [python 脚本]

crontab tee command doesn't write stdout into txt file, instead clears it [python script]

我有一个 python 脚本的 crontab 命令,它打印出目录中符合特定条件的文件。该脚本在 for 循环中打印出文件。然后我将该命令通过管道传输到另一个目录中的文件,然后通过另一个管道删除这些文件。

命令如下:

* * * * * ssh someserver.us.com "python /path/to/my/script.py | tee /path/to/my/text_file.txt | xargs rm"

我在 linux 中手动测试了这个,它输出到 txt 文件很好。

但是,当 cron 作业(使用相同的命令,但输出不同)运行时,它会清除同一个 txt 文件。

似乎只有在 cron 中才会以一种奇怪的方式工作..

我不太精通 cron 和 linux,所以任何帮助将不胜感激!

建议:将您的命令更改为 tee -a myfile.txt:

这是 "tee" 的文档:

http://man7.org/linux/man-pages/man1/tee.1.html