Skip to content

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 "python /path/to/my/ | 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!



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

Here’s the documentation for “tee”:

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