Skip to content
Advertisement

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

I have a crontab command for a python script that prints out files matching certain criteria in a directory. the script prints out the files in a for loop. I then pipe that command to tee the stdout to a file in another directory, and then remove those files through another pipe.

here is the command:

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

I tested this out manually in linux, and it outputs to the txt file fine.

however, when the cron job (using the same command, but for a different output) runs, it clears that same txt file.

it seems to be only in cron does this work in a weird way..

i’m not too well versed in cron nor linux, so any help would be greatly appreciated!

Advertisement

Answer

SUGGESTION: Change your command to tee -a myfile.txt:

Here’s the documentation for “tee”:

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

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement